How to send data via TCP

Hi all

I am trying to write a very simple application that will transfer data via TCP to another computer running a TCP server. (About 3K of data)

Although I followed the code example in the 4.6 Java Development Guide, page 101, on the use of the socket connections, (http://na.blackberry.com/eng/deliverables/3802/development.pdf) I've been running into questions that data transfer crashes after an undetermined number of bytes.

Someone at - it sample code to open a TCP connection and sending the data? This seems to be a very common thing to do, so I don't know what is my problem.

Thank you
Daniel

Advertisement

I'm not going to answer your first question, I think that we must resolve this problem before you watch something else (and I suspect they are all related).

I would almost guarantee that you run your socket send and receive on the thread of events.  The thread of events, that's what treats your interaction Menu, trackball movement etc.  If you perform a long running or blocking on this Thread, your device will freeze.

Look at the demo of Socket and move your network of transformation to a Thread separate, as does the sample.

To confirm that the treatment of your socket is executed on the event Thread, you can add this code, run it in the Simulator and watch it in the output window of the debugger and set a breakpoint on the line to System.out.

If {(Application.getApplication (), isEventThread ())}

System.out.println ("running in the thread of events and should not be");

}

Tags: BlackBerry Developers

Similar Questions

  • How to send data in eloqua with using ajax?

    Hello

    someone tell me how to send data using ajax?

    Thank you

    Rahul

    Hi Rahul

    Using this code to send data to AJAX

    $.ajax({)

    URL: ' your action? elqformname = name of the form eloqua & elqSiteID = eloqua site ID',

    type: 'POST',

    data: "field name =" + document.getElementById('field_id').value + "="+ document.getElementById('field_id').value field name,

    success: {function (html)}

    }

    })

    Thank you

    edynamic expert Eloqua

  • How to send data then other more via tcp

    Well guys, I am having some problems with it

    I have a program to labview that record and show for me in a chart, the voltages and currents

    now, I want to do a software... that I can follow the datas of my company...

    so I do a server/client via tcp

    and I've managed to pass data from one... but I need pass 6 data both

    I tried to make a tab control...

    But if I put the data received as a tab control

    the values do not change x)

    I put the server code and client...

    so maybe if you guys see

    you will understand!

    Thank you guys!


  • How to send data from the client to the server using tcp

    1. as I am new to watch I need help with sending data from client to server. I went through various examples of labview, but each of them also explains transfer of data to the client server. But I need help regardng send data from the server to the client.

    2.i would use the data type variant for sending my data.

    Can someone help me please. Thank you

    Regardless of the meaning. Once you have a connection each end allows it to send data to another. Just create what you want to look like interaction.

    Do you want the client sends a command that request data?
    How do you think the response data to look like?

    You can send variants, but probably not worth the effort.

    Mike...

  • sharing data via TCP/IP

    I finished by writing a LabVIEW program that I run in S.C.  It would be nice to watch some variables from my office here in OH.  Although we have several States apart we are on the same network domain.  I suspect that there is an easy way to do it.  Could someone point me in the right direction for the good vi or information?

    There is an example of 'several customers' that comes with LabVIEW. Just look for TCP/IP in the finder of the example. If you set up your code to handle multiple TCP/IP connections, you can have it send data to multiple clients (your computer being one of them)

  • Time increasing while sending data via http repeatedly on the storm

    Hi all!

    My application sends data (in general, this is a picture of ~ 1200 Kb) to the server via http.

    The data are sent ok, but the when I send data several times (without leaving the application) the time devoted to writing the data in the outputStream develops. On first use, it takes usually ~ 50 seconds, the second seconds of ~ 70, the third seconds from ~ 100... I see this problem only on the storm, others (Curve 8900, Bold, Tour) are OK. The url is used on Storm is: http://xxxxxxxxxxxxx.com/mobile/mobile.asmx;deviceside=true

    Here is the code snippet:

    private static WSResponse send(byte[] xmlBytes, WSResponseParser parser) throws Exception {
    
            HttpConnection connection = null;
        OutputStream outputStream = null;
    
           try {
                connection = (HttpConnection)Connector.open(WifiChecker.getURL(URL), Connector.READ_WRITE, true);
    
                connection.setRequestMethod(HttpConnection.POST);
                connection.setRequestProperty("Content-Type", CONTENT_TYPE);
                connection.setRequestProperty("Content-Length", String.valueOf(xmlBytes.length));
    
                outputStream = connection.openOutputStream();
    
                int offset = 0;
                int chunk = DATA_CHUNK_SIZE; // 1024
                int len = xmlBytes.length;
                while (offset < len) {
                    if (offset + chunk >= len) { // avoiding OutOfBounds Exception
                        chunk = len - offset;
                    }
                    outputStream.write(xmlBytes, offset, chunk);
                    offset += chunk;
                }
    
                xmlBytes = null;
    
                String response = getResponseAsSting(connection);
    
                WSResponse wsResponse = null;
                try {
                    wsResponse = parser.getWSResponse(response);
                } catch (Exception e) {
                    throw ApplicationException.invalidWsResponse();
             }
    
                if (!wsResponse.isSuccess()) {
                    throw new WSFailureException(wsResponse);
                }
    
                return wsResponse;
    
            } finally {
                IOUtils.safelyCloseStream(outputStream);
                IOUtils.safelyCloseStream(connection);
                if (xmlBytes != null) {
                    xmlBytes = null; // notify VM it can safely free the RAM
                }
            }
    

    I thought it may be a memory problem, so I manually cancel xmlBytes, but which does not solve the problem.

    Any ideas?

    Thanks in advance,

    Arhimed

    P. S.

    There is no question about Simulator, only on a real device of the storm.

    MSohm, thanks for your response.

    Fortunately, I have just fixed the problem. The problem was not in the code above, but in the code that made the xmlBytes. I converted bytes of the image base64 and looks like I did it dangerously on the use of the memory.

    Thanks again for your attention to this thread!

  • How to send data to a Web service

    Hello everyone. I have a very simple example of sending data (2222) to an existing Web service as follows:

     topmostSubform.Page1.SEND::click - (JavaScript, client)
    var url="http://Localhost:8080/4DWSDL";
    var serv = SOAP.connect(url);
    app.alert("hello ");
    serv.MethodeSOAP(2222);
    app.alert("hello 2");
    
     
    

    However, it works fine in Acrobat, but not in the drive. Is it possible to make it work?

    In addition, although in this example, the data to be sent are only worth 2222, but my goal is to send all the information from the form to a Web service. Someone has tried it before, or is there an other way easier to do? I would appreciate any suggestion on your part thanks

    Hello

    Via web service calls data connections will not work in the drive, unless the form has been activated in LC Reader Extensions ES2 to drive:

    I have a summary here:

    http://www.assuredynamics.com/index.php/2010/11/using-LiveCycle-Forms-in-Acrobat-and-Reade r.

    Hope that helps,

    Niall

    Ensure the dynamics

  • How to send data back to office applications

    Hi guys, I want to know all the possible ways to insert data in CRM OnDemand for legacy systems also the integration of options packages, it is best if you can tell me how to do it via web services, but no idea would be great. I ve heard talk of web links, but I Don t like that option so... can I do with the events of integration?

    Thank you!!

    There are several ways to extract data from CRM On Demand, including:

    * Export - Manual of the process, generate the CSV file containing data On Demand CRM
    * List/Analytics - manual process, export the contents of a list report to a CSV file
    Services - programmatic Web, developing an application that queries data within the CRMOD
    * Events - programmatic integration, use workflow to trigger the creation of the event and then query for events, namely that an operation occurs on a record (i.e. Insert new record of account)

    As to enter these data into another system, this will depend on the system and the methods for inserting data it makes available.

    I hope this helps.

    Thank you
    Sean

  • How to send data from CANOE to LABVIEW

    Hello

    I need to receive data from canoe in Labview.

    I prepared the VI (ex command.vi) sender and receiver VI (Simple UPD - receiver.vi) attached.

    My problem is:

    (1) when I run Canoe (arrested measure) and send the command start-> Canoe starts measurement. (OK)

    (2) when I run VI receiver and send the command Start-> receiver receives the command. (OK)

    (3) when I run the canoe, then run VI receiver and send the command start-> receiver VI receives command but DO NOT canoe starts measurement (canoe does not receive order). (NOK)

    I use the FDX Protocol (UDP-based) and it looks like canoe and receiver VI can work simultaneously on the same port (2809).

    How can I solve this problem?

    PS: Later I want to put the canoe in free run mode to control the Labview application so I need to work VI receiver with canoe.

    OK, now I get it.

    Is there a reason that you need three applications (transmitter + receiver + canoe) at the same time?

    Could not put the sender and receiver in a VI? That would solve your problem of port.

    Another way would be to send messages to general circulation, so canoe and the other VI can receive.

    A third option would be to send the message twice, once at canoe, once the receiver VI.

  • How to send data from c ++ to qml to an another qml.

    Hello

    I'm quite confused about a simple problem, I'm sure. Let me put some of my code and then I'll ask my question

    hand. QML

    // Default empty project template
    import bb.cascades 1.0
    import bb.data 1.0
    
    // creates one page with a label
    
    TabbedPane {
        Menu.definition: MenuDefinition {
            actions: [
                ActionItem {
                    title: "Refresh"
                }
            ]
        }
        showTabsOnActionBar: true
        Tab {
            title: qsTr("Employee")
            NavigationPane {
                id: everyonePane
                Page {
                    id: everyoneFeed
                    ListView {
                        objectName: "FeedView"
                        id: FeedView
    
                        layout: StackListLayout {
                            headerMode: ListHeaderMode.Sticky
                        }
                        listItemComponents: [
                            ListItemComponent {
                                type: "item"
                                DetailFeed {
                                }
                            }
                        ]
                    }
                }
                attachedObjects: [
                    ActivityIndicator {
                        objectName: "indicator"
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                        preferredHeight: 200
                        preferredWidth: 200
                    }
                ]
                onCreationCompleted: {
    
                }
            }
        }
        Tab {
            title: qsTr("TimeSheet")
            Page {
            }
        }
        Tab {
            title: qsTr("Calendar")
            Page {
            }
        }
    }
    

    detailView

    import bb.cascades 1.0
    
    Container {
        layout: StackLayout {
            orientation: LayoutOrientation.TopToBottom // this line stacks everything below
        }
        bottomPadding: 20
        Container { // single row
            id: row1
            // individual row container
            layout: DockLayout {
            }
            preferredWidth: maxWidth
            Container { // container for image
                preferredWidth: 150 //size of image if known
                preferredHeight: 150
                topPadding: 10
                leftPadding: 20
                horizontalAlignment: HorizontalAlignment.Left
                verticalAlignment: VerticalAlignment.Center
                ImageView {
                    preferredWidth: 150 //size of image if known
                    preferredHeight: 150
                    imageSource: "asset:///images/person.jpg" // some image
                }
            }
            // stack labels
            Container { // container for labels
                horizontalAlignment: HorizontalAlignment.Left // align this container to the left
                translationX: 200
                verticalAlignment: VerticalAlignment.Center
                layout: StackLayout {
                    orientation: LayoutOrientation.TopToBottom // this stacks the labels
                }
                Label {                objectName: "firstname"
                    text: "first label"
                }
                Label {
                    text: "second label"
                }
            }
        }
        Divider {
        }
    }
    

    Employee.cpp

    // Default empty project template
    #include "Employee.hpp"
    
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #include 
    #include 
    
    using namespace bb::cascades;
    
    QString mQueryUri;
    
    Employee::Employee(bb::cascades::Application *app) :
            QObject(app) {
        // create scene document from main.qml asset
        // set parent to created document to ensure it exists for the whole application lifetime
        mQml = QmlDocument::create("asset:///main.qml").parent(this);
    
        // create root object for the UI
        mRoot = mQml->createRootObject();
    
        // Retrieving my activity indicator
        //mActivityIndicator = mRoot->findChild("indicator");
        //mActivityIndicator->start();
    
        // Retrieving my list from QML
        mListView = mRoot->findChild("dribbbleFeedView");
        GetFeed("everyone");
    
        // set created root object as a scene
        app->setScene(mRoot);
    }
    
    void Employee::GetFeed(QString feedType) {
        // First off we initialize our NetworkManager
        QNetworkAccessManager* netManager = new QNetworkAccessManager();
        if (!netManager) {
            qDebug() << "Unable to create QNetworkAccessManager!";
            emit complete("Unable to create QNetworkAccessManager!", false);
            return;
        }
    
        // First off we initialize our NetworkManager
        netManager = new QNetworkAccessManager();
        if (!netManager) {
            qDebug() << "Unable to create QNetworkAccessManager!";
            emit complete("Unable to create QNetworkAccessManager!", false);
            return;
        }
    
        mQueryUri = "http://mycompany" + feedType;
        // We setup our url
    
        QUrl url(mQueryUri);
        QNetworkRequest req(url);
    
        // Setup the reply and connect to the reply function
        QNetworkReply* ipReply = netManager->get(req);
        connect(ipReply, SIGNAL(finished()), this, SLOT(onReply()));
    }
    
    void Employee::onReply() {
        QNetworkReply* reply = qobject_cast(sender());
    
        QString response;
    
        bool success = false;
        if (reply) {
            if (reply->error() == QNetworkReply::NoError) {
    
                int available = reply->bytesAvailable();
                if (available > 0) {
                    int bufSize = sizeof(char) * available + sizeof(char);
                    QByteArray buffer(bufSize, 0);
                    int read = reply->read(buffer.data(), available);
                    response = QString(buffer);
                    success = true;
                    Q_UNUSED(read);
                }
            } else {
                response =
                        QString("Error: ") + reply->errorString()
                                + QString(" status:")
                                + reply->attribute(
                                        QNetworkRequest::HttpStatusCodeAttribute).toString();
                qDebug() << response;
            }
            reply->deleteLater();
        }
        if (response.trimmed().isEmpty()) {
            response = "Request failed. Check internet connection";
            qDebug() << response;
        }
    
        bb::cascades::GroupDataModel* dm = new bb::cascades::GroupDataModel(
                QStringList() << "id");
    
        dm->setGrouping(bb::cascades::ItemGrouping::None);
    
        // parse the json response with JsonDataAccess
        bb::data::JsonDataAccess ja;
        QVariant jsonva = ja.loadFromBuffer(response);
    
        QVariantList feed = jsonva.toMap()["employee"].toList();
    
        QVariantMap player;
    
        foreach (QVariant v, feed)
        {
            QVariantMap feedData = v.toMap();
            dm->insert(feedData);
        }
    
        mListView->setDataModel(dm);
        mListView->setVisible(true);
    }
    

    OK so here is my question. I load a listview, in my hand, calling another qml, detailview. Given that my PPC is load my json file how can I send what I receive in my datamodel in my detailfeed can I change we tell the label with objectName: "firstname" to change the text for datamodel.name?

    Hope I am clear enough.

    Thank you

    I think that you can access ListItemData in detailView.qml. Say ListItemData.id.

    Why do you add only a mapping in groupdata. I think you need to add all the necessary fields such as firstname and so on. Right?

    bb::cascades::GroupDataModel* dm = new bb::cascades::GroupDataModel(
                QStringList() << "id");
    
  • How to send data from the Page with a form to fill out?

    How can I automatically include the page title or any text in my Web page when my client click on the Submit button in a form to fill out?

    This may seem obvious, but if you want to receive data from a form, and then place it in the form. A hidden form field with the title page and the text of your Web page will send these data on the form submission.

    best,

    Shocker

  • How to send data to another class?

    I have two classes, the main class and class data.
    Main class creates multiple instances of data class, and it also has a variable to the collection of the messages in this case. If the code goes like this:


    myData import;

    main/public class extends MovieClip {}

    report of the var: String;

    public void main() {}
    addEventListener (Event.ADDED_TO_STAGE, init);
    }

    private void init(event:Event):void {}
    var a: myData = new myData ("file to process 1");
    var b:myData = new myData ("process 2 file");
    var c:myData = new myData ("file in 3");
    }

    }

    Data class attempts to load the file specified from different locations, chargers, headphones, and others, and I would as as listener to report what happens during and after loading the data into the main class.

    public class myData {}
    public void myData(fname:String) {}
    Charger code "fname".
    COMPLETE and ERROR listeners
    }

    onError() {} function
    Send message to the report in the main class
    }

    function onComplete() {}
    Send message to the report in the main class
    }

    }

    It is the normal way of doing things and how do I make it work?
    I can not access the variable 'report' from inside the class, and I don't know if I can refer to the main class of inside the data class

    For example:

    package
    {
         import flash.events.Event;
         import myData;
         public class main extends MovieClip{
              public var report:String;
              private var a:myData;
              private var b:myData;
              private var c:myData;
              public function main() {
                   addEventListener(Event.ADDED_TO_STAGE,init);
              }
    
              private function init(event:Event):void {
                   a = new myData("file to process 1");
                   b = new myData("file to process 2");
                   c = new myData("file to process 3");
    
                   a.addEventListener(myData.COMPLETE, onComplete);
                   b.addEventListener(myData.COMPLETE, onComplete);
                   c.addEventListener(myData.COMPLETE, onComplete);
    
                   a.addEventListener(myData.ERROR, onError);
                   b.addEventListener(myData.ERROR, onError);
                   c.addEventListener(myData.ERROR, onError);
              }
    
              private function onComplete(e:Event):void {
                   removeListeners();
              }
    
              private function onError(e:Event):void {
                   removeListeners();
              }
    
              private function removeListeners():void {
                   a.removeEventListener(myData.COMPLETE, onComplete);
                   b.removeEventListener(myData.COMPLETE, onComplete);
                   c.removeEventListener(myData.COMPLETE, onComplete);
                   a.removeEventListener(myData.ERROR, onError);
                   b.removeEventListener(myData.ERROR, onError);
                   c.removeEventListener(myData.ERROR, onError);
              }
         }
    }
    

    And in the data class:

    package
    {
         import flash.events.Event;
         import flash.events.EventDispatcher;
         public class myData extends EventDispatcher {
              public static var COMPLETE:String = "loadComplete";
              public static var ERROR:String = "loadError";
              public function myData(fname:String) {
                   // 'fname' loader code
                   // COMPLETE and ERROR listeners
              }
              private function onError(e:Event):void {
                   // send message to report in main class
                   dispatchEvent(new Event(COMPLETE));
              }
              private function onComplete(e:Event):void {
                   // send message to report in main class
                   dispatchEvent(new Event(ERROR));
              }
         }
    }
    

    Post edited by: Andrei1

  • How to send sms via programmetically

    Hi friends,

    Here, I want to open the Textmessage field deal in that I want to put a default text and the user can choose the numbers he wants to send how to do this using bb api.

    Please help me friends.

    Thank you

    Check this box

    - http://docs.blackberry.com/en/developers/deliverables/11935/Create_new_populated_text_msg_565424_11...

  • How to send data from 150 morethen FlashVars

    Hello

    I need to send the data to flashvars, size is more then 150kb. This data set will be created by javascript.

    Thanks in advance.

    Chavigny

    use a return in your js function to return data to actionscript.

    You can use a timer loop to repeatedly query the js function and check whether the data is available.  When this is the case, put an end to the loop and use the data.

  • How to send data from the GET method?

    Dear all,
    I am trying to send a value list to a web server. Add the function to determine the value, I do not have here. The method I use is as below. I would like to know how is the value of the shipment to the web server that is the form of http://mysite:8080/test1/test1.aspx?myMessage=outputToServer. How to achieve this format?


    Try
    {
    URL url = new URL ("http://mysite:8080/test1/test1.aspx"); ")
    HttpURLConnection connection = () (HttpURLConnection) url.openConnection;
    connection.setDoOutput (true);
    connection.setRequestMethod ("POST");
    OutputStreamWriter writer = new OutputStreamWriter (connection.getOutputStream ());

    If (connection.getResponseCode () is HttpURLConnection.HTTP_OK)
    {
    Writer.Write ("myMessage =" + outputToServer);
    Writer.Close ();
    }
    on the other
    {
    System.out.println ("connection not found :");
    }
    }
    catch (MalformedURLException e)
    {
    System.out.println ("MalformedURLException");
    }
    catch (IOException e)
    {
    System.out.println ("IOException");
    }

    Remove anything to do with the writer.

Maybe you are looking for

  • Cannot display Web page but can on other browsers

    How can I fix this problem...http://cj.dotomi.com/ls72qgpo6/gns/54A98D84/6647CDB/4/4/4?d=waQL%3DCDAC9CGCAC%26in0zk%3D9%3C%3Cp11x%3A%2F%2F444.sy76nr.kwu%3AG8%2Fktqks-AA8BGHF-98EDCHC8%3C%3CO%3C%3C? It won't let me not see these pages. I can view using

  • Satellite Pro U200 - recover all of the WinRE partition system

    Hello I have PLUA1E Satellite Pro U200 - 02802QS4 with Vista Business.HOWTO recover the entire system of the WinRE partition?

  • Satellite A100-906: slow internet connection with Vista

    Hello world... I installed vista ultimate and I must say it's great... the problem is that the connection to the network is so slow... on xp, I used to get speeds up to 4.5 kb on my connection dial-up... on vista, I almost reach 1.5 KB... can someone

  • VI Scripting VISA Write / Read

    Hello I am using VI scripts to change the setting of the context menu for a node GPIB write or Read GPIB - Mode of e/s synchronous. I get the reference to the node GPIB write , but when I try to use the ToMoreSpecificClass function with the target GP

  • HP pavilion 2260sx g6 does not illuminate

    Hello guys, I turned off my computer hp laptop by pressing and hold the power button becouse take so more useuall in the opening... after when I turned it back to yesterdaty... it open habit and also no flicker no keyboard or power lights... so I'm c