• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client sends just 1 character to server (socket reset)

 
Siamak Saarmann
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I have this strange problem which has ruined my weekend.

I have been developing a client program for a server (which is developed in C). I was able to send full strings + different data types and get response from the server without problem.

Now (even though I think I have not changed anything), the connection resets after receiving first character of a string or first data item (like integer).

I receive this exception (after I receive a single character "V" at server side):

IOException: java.net.SocketException: Connection reset

Your help is very much appreciated.

My code snippet:


[ July 27, 2008: Message edited by: Siamak Saarmann ]
 
Siamak Saarmann
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again. I mad a little progress in debugging the reason.

1- I removed this line:

System.out.println("Server response: " + ir.readLine());

and I no more receive the exception. (what does this mean? The receive socket is synchronous blocking, why the connection is closed?)

2- After removing above line I start to send data:

If I comment th last line (writeByte) all write commands before it are received in server side. As soon as I un-comment the last line, only a single "V" character is received in server side (the server closes the connection?)

What is going on here. I am becoming crazy.

thanks.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to call "os.flush()" after doing all the writing, so any locally-buffered data is sent to the other end before you try to read the response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic