Forums Register Login

Client sends just 1 character to server (socket reset)

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Looky! I'm being abducted by space aliens! Me and this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2115 times.
Similar Threads
Exception in Socket Server
JAVA SOCKET PROGRAMMING
sending mail using servlet
How do I run a java file inside JSP?
simple socket programming
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:44:55.