Things about socket you should know

If you think that you are a master in socket programming, I believe you know that:

  • Calling serverSocket.close() (instance of ServerSocket) won't close the opened socket (created by calling serverSocket.accept()).
  • Once ServerSocket is instantiated and without calling serverSocket.accept(), client can build socket connection to the server.

    This should be a consideration in how to create codes. Think about this situation. A client assumes that the server has already hold the socket (through serverSocket.accept()). It then sends a message which requires a server response. But the server has not accept any socket call which means there will be no response for the client.

    So I think it's a good idea to let the server send a message to client so that client knows the server is ready to have a nice conversation.

Happy socket programming.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <pre>
  • Lines and paragraphs break automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter OPTIONS}...{/syntaxhighlighter} tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.