File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Client sends just 1 character to server (socket reset) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Client sends just 1 character to server (socket reset)" Watch "Client sends just 1 character to server (socket reset)" New topic
Author

Client sends just 1 character to server (socket reset)

Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 78
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 ]

PhD Artificial Intelligence, OCJP1.6
Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 78
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client sends just 1 character to server (socket reset)