I have a problem when you try to receive data using the socket connection.

Hello

I created a socket connection between a pc (sever, win32) and a blackberry (client) and I have only two questions:

-When I send a string to the sever I get the unexpected result, I doubt if it's a problem of encoding between platforms.

-When I try to receive data, (an array of char as a string object), the customer demand freeze (drawing and management of events, so basically the main UI thread), even if I did all the stuff of connection in a separate thread, until I have shut down the server and also no data is received.

I left the codes below and would assess any response from you.

C++, win32 console application:

SOCKET _Socket;

int _tmain (int argc, _TCHAR * argv)

{

If (start_sever (_socket)) {}

char r_msg [26];

recv (_socket, r_msg, 26, 0);

std::cout< "receive="" :="" "="">< r_msg=""><>

char * s_msg customer = 'welcome ';

Send (_socket, szMessage, strlen (S_MSG), 0);

std::cout< "send="" :="" "="">< s_msg=""><>

Sleep (500);

Shutdown (_socket, SD_SEND);

closesocket (_socket);

WSACleanup();

} else {}

std::cout< "cannot="" initialize="">< std::endl="">

}

System ("pause");

return 0;

}

BOOL start_sever (socket) {}

WSADATA WsaDat;

If (WSAStartup (MAKEWORD (2.2) & WsaDat)! = 0)

{

std::cout<"WSA initialization="">

WSACleanup();

System ("pause");

Returns false;

}

Socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);

if(Socket==INVALID_SOCKET)

{

std::cout<"Socket creation="">

WSACleanup();

System ("pause");

Returns false;

}

SOCKADDR_IN serverInf;

serverInf.sin_family = AF_INET;

serverInf.sin_addr.s_addr = INADDR_ANY;

serverInf.sin_port = htons (8888);

If (bind (Socket,(sockaddr*) (& serverInf), sizeof (serverInf)) == SOCKET_ERROR)

{

std::cout<"Unable to="" bind="">

WSACleanup();

System ("pause");

Returns false;

}

Listen(Socket,1);

SOCKET TempSock = SOCKET_ERROR;

std::cout< "build="">

while(TempSock==SOCKET_ERROR)

{

std::cout<"Waiting for="" incoming="">

TempSock = accept (Socket, NULL, NULL);

}

Socket = TempSock;

std::cout<"Client>

Returns true;

}

Platform of Java for blackberry:

public class Bush extends form {}

-my current ipv4 address is set by default to avoid reset at each test

TextField ip_text_field = new TextField ("IP address:", "192.168.65.1");

-the server is waiting for any connection to this port ("8888")

TextField port_text_field = new TextField ("Port:", "8888");

ButtonField go_button_field = new ButtonField ("Connect", Field.FIELD_HCENTER) {}

protected Boolean invokeAction (int action) {}

UiApplication.getUiApplication () .invokeLater (new Runnable() {}

public void run() {}

try {

open_connection();

}catch (System.Exception e) {}

e.printStackTrace ();

Dialog.Alert (e.getMessage ());

}

}

});

return true;

}

};

public Socket() {}

Super ();

setTitle ("[taking sample]");

Add (ip_text_field); ip_text_field.setMargin (20, 0, 0, 0);

Add (port_text_field); port_text_field.setMargin (30, 0, 0, 0);

Add (go_button_field); go_button_field.setMargin (30, 0, 0, 0);

}

public Boolean onClose() {}

this. close();

return true;

}

_Con StreamConnection;

DataInputStream _in;

OutputStreamWriter _out;

public Sub open_connection() throws Exception {}

_CON = (StreamConnection) Connector.open ("socket: / /" + ip_text_field.getText () + ":" + port_text_field.getText () +)

» ; deviceside = true; interface = wifi");

this.add (new TextField ("", "connected successfully to Server"));

_in = _con.openDataInputStream ();

_out = new OutputStreamWriter (_con.openDataOutputStream ());

String msg = "Welcome to customer \r\n";

_out. Write (MSG);

String r_msg = _in.readUTF ();

this.add (new TextField ("read from sever:", r_msg));

_out. Flush();

_in. Close();

_out. Close();

_CON. Close();

this.add (new TextField ("", "data has been changed"));

}

}

Thanks for your help.

You treat on the thread of events.

You have the following code:

UiApplication.getUiApplication () .invokeLater (new Runnable() {}

public void run() {}

try {

open_connection();

.....

Now invokeLater essentially tells the operating system that the associated executable must be run on the event Thread.  You need start a separate Thread.  Extend this Thread, add your code in the run() method, and then start the Thread with start(). (not run()).  Then you must run the networking of processing on a separate Thread.

This will cause you problems updating the user interface.  Take a look at this help:

http://supportforums.BlackBerry.com/T5/Java-development/update-a-screen-on-the-main-event-thread/TA-...

Printing, this means that invokelater a separate Thread is a common misconception.  I recommend you to look at this:

http://supportforums.BlackBerry.com/T5/Java-development/what-is-the-event-thread/Ta-p/446865

In addition, I recommend that you take a look at the socketDemo which must be included as a sample-, otherwise you can find it on github:

https://github.com/BlackBerry/JDE-samples

Tags: BlackBerry Developers

Similar Questions

  • I suddenly have a problem when you try to download I get this message. "Cannot transfer to Internet Download manager." 0x8002801D error

    Error of the IDM

    I suddenly have a problem when you try to download I get this message. "Cannot transfer to Internet Download manager." Error 0x8002801D in windows XP. Pleasw help to y for remedy.
    Thank you

    Hello

    (1) what you're trying to download?

    (2) how you try to download?

    (3) what browser you are using to download?

    (4) don't you make changes to the computer until the problem occurred?

    Step 1: This error occurs when your browser and IDM are set to run under different privileges.

    Maybe you have set to run IDM with administrator rights. This is not correct. IDM Ouvrezledossier if please, right-click on 'IDMan.exe', select the 'Properties' menu item, switch to the "Compatibility" tab and uncheck the checkbox "Run this program as Administrator" (arrow 2 on the image). In addition, you must remove the compatibility with previous versions of Windows if there is none activated (arrow 1 in the picture).

    If this does not help, try to do the same for the executable file of your browser. In addition, turn off the feature with older versions of Windows and "Run this program as Administrator" checkbox.

    Step 2: You may need to run IDM with administrator once rights to register its DLL files. Exit IDM using "Tasks-> output" of the main menu. Then right click on IDM launch icon in the Windows (arrow 1 in picture) programs launch menu and select "Run as Administrator" (arrow 2 on the image).

    Then exit IDM again and run normally.

    Hope this information is useful.

  • [4.0] production SQL Developer crashes when you try to extend Java in the browser connection

    People,

    I'm under production Developer SQL on Oracle Linux 5.8 and whenever I click on the link Java in browser connections with a SYS AS SYSDBA SQL Developer connection is suspended.

    Oracle Enterprise Edition 11.2.0.1.0

    SQLDeveloper 4.0.0.13.80

    Oracle Linux 6

    JDK Version 1.7.0_45

    Do the same with the user SCOTT (no SYSDBA) works very well (although there is no Java objects).

    Thank you

    Rich

    This was noted as a bug.

    The bad plan/performance was recorded as a bug. Developer SQL has not hang for me - I was able to cancel the query using the Panel on the progress of tasks.

  • Hi I have a problem when I try to make phot I stacking Photo shop stop program to react and stack thank you elimor

    Hi I have a problem when I try to make phot I stacking Photo shop stop program to react and stack thank you elimor

    Finally, I solved the problem

    I just did a new version update

    And everything works as it should

    I thank all the helpers

    Thank you!!!

  • Windows media player error "Windows Media Player has encountered a problem when you try to read the file" after burning CDs.

    Original title: "missing songs" in my windows media player then burn them on several cd :((

    I burned songs to several cd using my Windows media player to make different Cd, but after I returned to my library all the songs that I burned to the CD have disappeared, they are there, but they won't play it is as if they have been deleted, a window appears saying that windows media player has encountered a problem when you try to play the file. I did not notice this until after Cd burning a few I can't do more because if I keep going I'm not going to have more songs in my library! I don't know what to do im going crazy, it took me a long time to get all of these songs and now he disappeared! I have Windows 7 Ultimate is the version 12.0.7601.17514 hope that helps

    Hello
     
     
    They were playing before you burn CDs?
     
     
    Method 1:
    Open the troubleshooting Windows Media Player settings Troubleshooter
    http://Windows.Microsoft.com/en-us/Windows7/open-the-Windows-Media-Player-settings-Troubleshooter

    Method 2:
    This problem may be due to database corruption. You can delete the Windows Media Player database and check if the problem persists.

    Steps to clear the database of windows media player:

    a. exit Windows Media Player.
    b. Click Start, run, type %LOCALAPPDATA%\Microsoft\Media Player and then click OK.
    c. Select all files in the folder and then click on Delete on the file menu.

    Note you don't have to remove the folders that are in this folder.

    d. restart Windows Media Player.

    Note: Windows Media Player automatically rebuilds the database.

    If this does not resolve the problem, disable the Windows Media Player database cache files. To do this, follow these steps:

    a. exit Windows Media Player.

    b. Click Start, click Run, type % LOCALAPPDATA%\Microsoft and then click OK.

    c. Select the Media Player folder, and then click on Delete on the file menu.

    d. restart Windows Media Player.

    Note Windows Media Player automatically rebuilds the database.

  • I use a PC.  Problem: When you try to export my photo developed in the library, a message appears that says, "can't export, or offline or missing Source files."  How can I get my picture exported to my hard drive?

    I use a PC.  Problem: When you try to export my photo developed in the library, message box appears that says, 'impossible to export... '. Offline or missing source files. "How to fix this to export my photos on my hard drive?

    Lightroom is not in the expected location that he thinks that the photos are in the photos.

    This can happen because you have (perhaps accidentally) moved, renamed or deleted photos or folders containing them outside of Lightroom.

    The solution is to use your operating system to find the new location of the photos. Take note of where they are. Then in Lightroom, you can reconnect to them through these instructions: Adobe Lightroom - find folders and files moved or missing

    As an alternative, if the files were simply moved (and not renamed or deleted), you can use your operating system to move towards where Lightroom is expected to make them.

  • I have a problem when I try to install indesign CC - error: 5

    I have a problem when I try to install indesign CC - error: 5.

    Last week I change Windows 10.

    How can I fix?

    I suggest you to contact our chat/telephone technical support teams as they can remote into your machine and help.

    Contact the customer service

    *Remember to stay signed with your Adobe ID ( email id used to purchase the subscription ) before accessing the link above*.

    Select the exact options indicated below in the capture to get support of screen options:


  • I recently downloaded a program on my computer by mistake. When you try to uninstall, I get the message that I don't have authority to remove the program

    I recently downloaded a program on my computer by mistake. When you try to uninstall, I get the message that I don't have authority to remove the program and contact the system administrator. I am the administrator and logged as such.

    See if that helps.

    How to take possession of an item in Vista. Works also under Windows 7
    http://www.howtogeek.com/HOWTO/Windows-Vista/add-take-ownership-to-Explorer-right-click-menu-in-Vista/

    And possibly:

    Revo Uninstaller
    http://www.revouninstaller.com/revo_uninstaller_free_download.html

  • I had the creative cloud now for 4 months, but it says I don't have a subscription when you try to use PS, but I connect to Adobe and I do?

    I had the creative cloud now for 4 months, but it says I don't have a subscription when you try to use PS, but I connect to Adobe and I do?

    I have download it again and he takes me to a page where it wants a serial number, I'm something wrong or missing something?

    Your subscription to cloud shows correctly on your account page?

    If you have more than one email, you will be sure that you use the right Adobe ID?

    https://www.adobe.com/account.html for subscriptions on your page from Adobe

    .

    If Yes

    Some general information for a subscription of cloud

    Cloud programs don't use serial... numbers you, connect you to your cloud account paying to download & install & activate... you may need to sign out of the cloud and restart your computer and log into the cloud for things to work

    Sign out of your account of cloud... Restart your computer... Connect to your paid account of cloud

    -Connect using http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html

    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    -ID help https://helpx.adobe.com/contact.html?step=ZNA_id-signing_stillNeedHelp

    -http://helpx.adobe.com/creative-cloud/kb/license-this-software.html

    .

    If no

    This is an open forum, Adobe support... you need Adobe personnel to help

    Adobe contact information - http://helpx.adobe.com/contact.html

    Chat/phone: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    -Select your product and what you need help with

    -Click on the blue box "still need help? Contact us. "

  • When you try to print a document, the fax MACHINE pop up screen

    Hello

    When you try to print a document, the FAX screen pop up, so I can't print.

    I don't know ho to avoid that from happening.

    Please advice.

    AVI

    > Where these two printers are defined?

    Printers/FAX page.

    > I'm in Chrome and I right click, print, then it brings me the FAX screen pop up

    In chrome, I see a page that lists the printer (which is listed for you?) and a button saying 'change '.

    Also, if you use ctrl-shift-P, it gives the system dialog.

  • error code 0 x 80246007 appears when you try to install updates and the windows store purchases.

    error code 0 x 80246007 appears when you try to install updates and the windows store purchases.

    any help appreciated

    Original title: error code 0 x 80246007

    Hello

    Please try the patches for Windows Updates:
    And for store related issues, use Troubleshooting Windows App tool:
    Hope this helps, good luck :)
  • Problems when you try to move the 3 stepper motors

    Hello

    I have problems when I Isaiah to compile a 3 stepper motors control program.

    I have 3 steepest motors and controller (3 SMCP33 + SMCP33-EVA) nanotec.com, they also provide an example of Vi to control a motor that works successfully, but problems happen when I try to adapt the program to try to start the 3 Motors. The final application for this is going to be a Cartesian robot XYZ so finally I need to program coordinates to move the 3 Motors.

    I am new to LabVIEW, so what I do is try to adapt the nanotec example to order 3 engine as follows.

    -J' I assign each engine a different address, doing so that I can run each engine separately. But when I try to run 3 programs at the same time, they work but all moving them the engine (the first that has been run).

    -If I try to make a sort of sub - VI is the same thing, only one motor is driven.

    -Moreover, I get a warning when I try this, I have attached a screenshot of this.

    I have attached the Vi and texture it to improve my description.

    I woul be grateful if someona can help aport.

    Kind regards.

    Thanks for posting the original.  By comparing the two screws immediately gives an indication of what might happen.

    In the picture you posted you circled two places where you changed the address of the reader. In the Example.vi - Nanotec address of the player is connected to about 14 seats.  So when you try to run the other engines in your modified program, the 12 places, you have not changed the address of the player are always preset to motor 1.

    What you need to do is to divide the example VI in at least three parts.  The first part initialization. The next part moves the engine.  The last part ensures that the engine is stopped and made any required another stop.  Each party becomse a separate Subvi. Each Subvi has the address of the reader as input.  The initialization and shutdown parts are placed before and after a while loop.  The movement parts are inside the loop.  You can use three of each sub - VI for the three engines or a Subvi combined with subVIs move three to manage all three engines.

    I can't say what approach might be better without knowing more about how you plan to order the engines - one at a time or all three at the same time, what kind of feedback is used, how management mistakes and other topics.

    Lynn

  • Have a problem when you create or open project

    Only, I could get V1 to work with administrator privileges, otherwise he threw the message "Adobe Premiere Elements has encountered a problem and needs to close"

    So I've upgraded to V10, but now click on the same block with users with administrator privileges.

    Occurs when I try to create a new project (when you click OK after entering the new details) or when you try to open an existing project.

    When you create a new project files and home folders are created before the error message and crash.

    I use Windows XP SP3 with all latest updates.

    So I can't anything with PE10.

    Error code is 0xc0000005

    Flag 0 x 00000000

    Folder 0 x 000000000000000

    Address 0x00000000196cd0a3

    Any ideas?

    Davyxyz

    Are you using Premiere Elements on a base of home computer a user to a network at work or school? I ask because you wrote "..." his block with the users with administrator privileges. ?

    Let us look first at your computer resources.

    Windows XP Professional SP3 32 bit

    The amount of RAM is installed and the amount of RAM available? How much free space on the hard disk on the Local C drive? What is the capacity of the Local C drive? Work with additional hard disks internal or external? If so, how they are formatted?

    You have the latest version of QuickTime installed on your computer?

    Have you checked that your video and audio card drivers are updated according to the web site of the manufacturer of these cards, not only the Device Manager?

    Please confirm the earlier version of Premiere Elements you used... has this elements 1 first?

    Let us start here and then decide what then.

    Thank you.

    RTA

  • Problems when you try to play Texas Hold em

    When you try to play Texas Hold em, I get to 'Play now' and no further. There is a simple solution, but there is no need to be corrected download prompt. Help

    Hi patrick Gray,.

    According the description preceding, you aren't able to play Texas Hold em.

    1. what operating system is installed on the computer?
    2. what happens when you click on 'play now', you get the error message?
    3. are you able to play other games?
    4. don't you make changes to the computer before the show?
    5. what web browser are you using to play the game? If you are using Internet Explorer, version of Internet Explorer you are using?

    If you use Internet Explorer, then I suggest you to try the steps from the following link:

    The problems of games online using Internet Explorer
    http://support.Microsoft.com/kb/2528246 post us the results once you try the steps above.

  • Password problem when you try to download.

    Mac OS x.  Change password that allows me to connect, but not accepted when you try to download.

    This password is presented by your operating system and is designed to prevent you from accidentally installing the software.

    If it comes to your personal computer and you don't need a password to connect to the computer when it first starts, you can probably leave the password blank and click OK to go to this prompt.  If it comes to your personal computer and your normal password does not work, make sure that CAPS LOCK SHIFT is off, and then type the password carefully.

    If this is your work machine and he asks an administrator password, well, you will need to have a conversation with your computer friendly.

    If you are still puzzled, you may need to reset the password on your Mac:

    http://support.Apple.com/kb/PH18653

    http://support.Apple.com/kb/PH14325

    http://support.Apple.com/en-us/HT201240

Maybe you are looking for

  • WiFi internal

    I have a 500-281 with internal wifi Pavilion. Cell, T.v or my kindle connect to this wifi. It straightens my neighbors router. Thanks for any help on this.

  • What is BitGuard?

    I found a program on my computer called: BitGuard.  I searched on the internet for more information and found nothing.  Anyone know what is this software? Thanks a lot for your help!

  • all programs fine EXCEPT QUICKEN 2013, that file opens with dei message low

    Have windows xp professioinal, operational, with the exception of transactions quicken 2013. When quicken is openedit opens reduced with message LOW RESOLUTION SCREEN, I can reduce this window and increase the DPI, but the window is to small for me t

  • My computer just won't start in safe mode...

    My computer just won't start in SafeMode... after the signs up to 'safe mode' and pushing enter... it stops (no signal) and normally restarts itself! I need to get rid of malware and infections in the start up... hmmmmm

  • Data Execution Prevention has closed Itunes

    I have a terrible time trying to get my Itunes to work. However, there seems to be a problem with Data Execution Prevention do not allow me to open the program. I followed the steps and checked the boxes that Itunes and Quicktime would be allowed. Ho