Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket read never getting reply to second message

 
Tom Salyers
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a class that just opens up a socket to a server, sends about four messages, and then closes the socket and quits. My problem is that when I read the input stream, the response from the first message is there, which is fine....but when I send the second message and read the input stream, not only is the first response still there, the second response is nowhere to be seen. I've attached the relevant portion of the code snipped from the method.
A couple of notes...the calls to "d2mb" you see are to another class of mine that just inserts various characters into specific places in the given StringBuffer.
MAX_MSG_LEN is 650, and nothing we're dealing with below is longer than about 90 characters. I've got catch blocks in the rest of the method for the exceptions that might be generated.

Any ideas?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any obvious problem. You probably ought to be saving the lengths return by in.read(buf, 0, max_length) and maybe logging them to see what they are.
 
Tom Salyers
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed my problem--I'd tried using skipBytes() to skip over the previous message's response, but that would hang and the read would time out. Turns out if I call skip() with the number of bytes in the first message response, I get the second one just fine. Thanks for looking at the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!