Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 57
Registered: ‎09-22-2010
My Device: Not Specified
Accepted Solution

Stream socket communication I/O operations

Hi!

 

I want to build a mechanism that opens a socket connection to a server and then independently send and receive messages to and from server on this connection. My approach is like this: from main thread I launch a thread (ignition thread) that opens a StreamConnection (socket://ip:smileytongue:ort;deviceside=true) and get DataInputStream and DataOutputStream objects out of it. Using DataInputStream I create another thread (since reading and writting will be independent - wondering still if it is possible) only for input data. I will then use a notification mechanism to use received data.

DataOutputStream is then used for writting operations ...

 

Problem I have:

Writting seems to be fine as I can see logs just before and after DataOutputStream writeUTF and flush methods, but the reading fails with a "General " IOException. Now, I assumed this StreamConnection can handle independent input / output operations ... If not, is there a way of doing it?

 

Has anyone done this independent in and out operations?

 

 

Regards,

gunar

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Stream socket communication I/O operations

From memory, other people have reported issues with attempting to process the same socket connection connection in different directions using different Threads.  I would not do this.  If you need full duplex, then start a second socket. 

Regular Contributor
Posts: 57
Registered: ‎09-22-2010
My Device: Not Specified

Re: Stream socket communication I/O operations

Hi Peter,

 

Thank you for your response! ... I haven't found anything related to my problem and I didn't find anyone having the same issue. Do you remember where have you seen posts with sharing the same socket connection in 2 threads?

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Stream socket communication I/O operations

Has to be in this forum, but good luck searching for it.....