This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Socket Programing using TCP Protocol Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Socket Programing using TCP Protocol" Watch "Socket Programing using TCP Protocol" New topic
Author

Socket Programing using TCP Protocol

Thamaiyanthi Pitchaimuthu
Greenhorn

Joined: Aug 20, 2010
Posts: 14
Hi All,

Am developing the client application using Socket class(TCP Protocol), which will read the data packet continously from the Server socket which will have the header and payload. Header part will have message length length) using the same am reading the (in data packet 2 bytes for message remaning data) . the problem is here some times am getting the message length 65535.
Am in very big confusion why it is coming whether the problem in my application or in tcp connection. please i need your help to trouble shoot.

Thanks.
Thamaiyanthi.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Post the complete error message and the code that's causing it, preferably an SSCCE of both client and server.
Thamaiyanthi Pitchaimuthu
Greenhorn

Joined: Aug 20, 2010
Posts: 14
(Really Sorry for my mistake while editing the code i missed out) can you please check now . i use code only now..
Thanks..
Am developing only client application, am not aware of Server,
i will not get any exception stacktrace and all, while reading message length simply i will get Message length =65535 which is the maximam value of unsigned 16 bit.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
I assume by "i will get Message length =65535" you mean that the "if (length == 65535) { ... }" block is executed? That's odd, since the "if (length == 0) { ... }" block before it should always be executed, seeing that the readMessage method always returns 0 (unless it throws an exception).

You should edit your post to UseCodeTags, by the way. Makes it much easier to read.
Thamaiyanthi Pitchaimuthu
Greenhorn

Joined: Aug 20, 2010
Posts: 14
Thanks for your response..

okay i will code tags,

No that message length always wont be 0, i would get like 139,201. so in some cases only i will get message length is 0 like socket closed.. my doublt is why am getting 65535, where the thing going wrong whether in my code or tcp connection.
this is going as a very big issue..
Thanks..
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Sorry, I meant messageLength, not readMessage. While the "message length" may not always be 0, the result returned by the messageLength method will always be 0 - check its code. And please edit the post to use code tags.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Socket Programing using TCP Protocol
 
Similar Threads
Sockets, Multiple Clients, and i/o.....mind blowing!!!
Networking performance questions
file transfer using datagram
TCP, UDP,IP
how to minimize packet loss in UDP transmission