In a java socket client server program involving client GUI, bearing in mind the below :
Client / server interaction would not be continuous, meaning that an end user might have the GUI left open but would only press buttons / initiate requests every once in a while.
Server would initiate a new thread for each client
All I/O would be via ObjectInput/OutputStream
So based on the above what would be the best approach on the connection/socket creation :
What are the pros/cons of using one over the other?
Many thanks
For a requests initiated by user "click" i would use the 2nd mode where you open and close connections for every user action separatelly. This will allow you not to keep multiple open connections forever. Keeping connections forever could lead to many problems of resource exhaustion type. If you don't have really important reason to keep open connections eg. that you need to respond to the client with some live messges like a chat, but rather can respond directly after request then it would be much simpler to not keep the connection. It is always better to not keep open idle connections if you don't have to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.