Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

strange results  RSS feed

 
Hiep Nguyen
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just started learning socket programming in java. My programe has two part. one is client creates a message that is sended to server. Another is a server that recives the messages and then send back the message to client.
it work but has a strange result. the first char in the message, for sample "123", that sended from client to server,at server side, it's removed, so the result is "23", again the recived messages are sended back to client, so the result at client ":23". I don't know result.
has any one can help or explant ?
thank you !
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Impossible to see without code, but I'm willing to bet that it has nothing to do with your network programming per se -- check your stream I/O code to see if you're throwing away stuff.
- Peter
 
Abhijit Kulkarni
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two probable reasons that I can think of:
1. The if you are using any buffer or an array for the i/o stream you are probably not flushing it. Check if the results vary. Rerun or call the sequence in a loop and read the data in a loop in the server side.
2. Or perhaps your code does not encode the data in the right charecter set. try encoding the data.
This can be better clarified if you can paste the code.
e.g. the type of OutPutStream object you are using and teh piece of code used to write to socket.
I hope this helps!

[ June 18, 2002: Message edited by: Abhijit Kulkarni ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!