If i have two servers that are continuously running and sending messages to each other should I:
a) for each message to be sent : create socket, get output stream, send message, close stream, discard socket? b) continuously maintain sockets and streams between servers?
Basically, is there any issues with keeping hold of a socket for as long as the servers are running, or should I be reconnecting regularly?
posted 12 years ago
I would just keep one socket around. Sometimes when there is network congestion, an open socket pair will stay functional even when new socket pairs cannot be connected.
However, brief router outages can cause loss of connection, so even if you just use an open socket, you have to think about what to do if it goes down. Typically, you would just reopen the connection, and possibly resend any failed messages.