开发者

Networking issue from java ServerSocket to iphone (only on 3g mode)

I am experiencing weird behavior:

I have a server, based on a java ServerSocket that serves TCP request that are send from iPhone device. I have noticed that when I use the iPhone is connected开发者_Go百科 via wi-fi, there are no problems with the networking. The iphone opens a connection and than write and read from the stream as it should, with no noticeable latency. So far so good. Working with 3g, however, I am experiencing 1.5 seconds latency from the second the first message is sent until the response is fully arriving back. It seems that the first byte of the message is read right after the server flushes the message to the socket, but the rest of the message is being delayed for about a second(!).

I verified this network behaviour by both printing the buffer size that arraive on the iphone side and by monitoring the networking with wireshark on the server side. Wireshark shows this as well - the first byte, is sent in a 1 byte message size (it is always 0 BTW), and the rest of the message is sent afterwards, in one or more large messages (~1300 bytes).

The message is composed of an 8 byte header (2 integers - type and size), and a body of that size.

The real weird thing is that writing similar server that uses the same protocol in c++ (using poco server), is working perfectly.

I use the DataOutputStream of the socket to write the header using 2 writeInt instructions and a write(byte[]) that writes the body. I then flush the stream.

Does anyone knows if there's a socket option (in java) that can cause this kind of behaivour?

Any help will be appreciated.


I solved that issue, by wrapping the socket output stream with a BufferedOutputStream:

DataOutputStream dos = new DataOutputStream(new BufferedOutputstream(sock.getOutputStrean()));

Thanks, Lior


I suggest that you post your server's Wireshark trace as this may provide some insight into what TCP socket options are configured and the timeline from the handshake to the first data transer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜