07-30-2007, 02:41 AM
Thumbs Must Hurt
Join Date: Jun 2007
Post Thanks: 0
Thanked 0 Times in 0 Posts
| | A problem of receive data by socket
Please Login to Remove!
these days, I'm working reveive data from server by socket ,but there is always a problem confuse me, can anyone give some advice?
The function ReceiveMessage is as follow:
public int ReceiveMessage(String UrlServer)
int n=1;//total send 10 times
StringBuffer buffer = new StringBuffer();
StringBuffer buffer1 = new StringBuffer();
DataOutputStream outStream = null;
DataInputStream inStream = null;
SocketConnection sock = (SocketConnection)Connector.open(buffer.toString() );
outStream = sock.openDataOutputStream();
inStream = sock.openDataInputStream();
//send message to server
if (n < 10)
buffer1.append("this is the ");
buffer1.append( n );
buffer1.append("th times send message!");
//read the message
int len = 0;
byte outByte = new byte;
while ((len = inStream.read(outByte)) != -1)
} //end while
} // end try
System.out.println("there is an error :" + io);
The server is written by C++ and it receives the messages sent from client,
while it also sends the message to me according the received message.
The problem is :
when I debug the program, the program always stop at the sentence :while ((len = inStream.read(outByte)) != -1), and after about one minute it's catch an error which says the connection timed out!
I can see from the server screen that the messeage from client has been received, and the message to client has been sent, but my program stop at inStream.read(), so can anyone tell me why?
Thank you very much!
Last edited by streamh : 07-30-2007 at 02:43 AM.