Socket is still connected after Server-Side socket termination.



Basic Idea
So I have this client-server project where the client uses Java's
Socket class to communicate with the server using JSON. Let's say that
I have a fake message that the client sends to the server and the
server closes the socket with the client (it doesn't send any response
to the client). In the client side I have a Thread that loops through
the socket's inputstream and prints out any server response. I also
print out the socket's connection status (socket.isConnected()).

Problem
When the client first sends the message the server immediately closes
the socket (I also terminate the server to make sure). The client, on
the other hand, never gets notified that the socket is closed and
everything seems running normal (it still prints out "true" every
socket.isConnect() method call). Only after a few attempts of sending
a message will the client understand that the socket is closed and
tries to reconnect.

Structure
SockeEngine is a class that handles the thread and has a
BlockingQueue<String> for outgoing messages. The thread loops forever.
The loop looks at the queue, the inputstream and outputstream. When
the queue has a message(s) to send it writes it to the outputstream of
the socket. After that it reads the inputstream and finnaly sleeps for
100ms.

I heard that the way we wrote it isn't the problem. We think the
problem relies on the implementation of sockets in Java or Windows. We
also think that it most likely not. Our temporary solution is sending
a termination message from the server to the client and then closing.
Any ideas/suggestions?

Thank you very much for your time.
-pek

.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)

Loading