Reputation: 685
I am in the process of developing a game and I have a question.
I have a client where a user can log in to the game or disconnect using a unique account stored on a database.
How do I properly close a server on log out and re open on log in? Or should I never close the socket? The same question goes for DataInputStream and DataOutputStream.
I keep getting connection reset client sided, so I don't know what the best way to handle logging in/logging out within the same client runtime.
Thanks. :)
Upvotes: 0
Views: 593
Reputation: 310911
Just close the socket. That will terminate the corresponding thread at the server. One login should equal one socket.
You should do that by closing the outermost stream or Writer wrapped around the socket output stream. That flushes it and closes the other streams and the socket. Closing the input stream and the socket before this is incorrect, and doing so afterwards is redundant, but if you must do it it must be done after, not before, otherwise again you miss a flush.
Upvotes: 1