My client-server program seemed to work fine, I could send and receive messages.
But if I don't send any messages for a while (sometimes 2 minutes is enough, other times it takes an hour..) and then try to send one, I get the error "Software caused connection abort: recv failed" on this line:

System.out.println("[_in_"+(line=ins.readLine())+"_]");

ins being

ins = new BufferedReader(new InputStreamReader(_sock.getInputStream()));

and _sock being

Socket       _sock      = null;
_sock = serv_sock.accept();

I modified my code to send something every minute and it the same problem hasn't happened again.

Why did I get that error?

Is it a windows/network thing that closes tcp streams if inactive?
Can that even be it? Since the duration varied - a lot.

Or perhaps its readLine() or a Socket issue?

Can you disconnect/reconnect on failure and, if so, are you able to send and receive messages then? If its a problem with networking this should work. Also, are you using UPD or TCP?

Can you disconnect/reconnect on failure and, if so, are you able to send and receive messages then? If its a problem with networking this should work. Also, are you using UPD or TCP?

It's TCP.


About "Can you disconnect/reconnect on failure and, if so, are you able to send and receive messages then?", not completely sure what you mean.
When I get the error, the server java shuts down.
I can restart the server and client and it will work again, if that's what you mean?

When that line throws an exception, my code closes the socket.

It happened again.

I tried sending a message from my client to my server - nothing happened.
I tried a few times and then (on the client) the recv failed error popped up.

(during this time I had WireShark up, it listed a few [TCP retransmission]s)

I then went to my server and tried sending - resulting in the same error.

What I was suggesting was to catch the exception, have the client disconnect and reconnect to the server (or vice versa), then try resending the message.

Did WireShark show incoming and outgoing or just outgoing transmissions?

What I was suggesting was to catch the exception, have the client disconnect and reconnect to the server (or vice versa), then try resending the message.

Did WireShark show incoming and outgoing or just outgoing transmissions?

It was showing both incoming and outgoing.

Is it a windows/network thing?
Anyone who can help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.