hello from some books, i learn that after sending the data,the socket port should be closed,but consider my scinario: my project is consisted of two subsystem,let me call them:sysA and sysB,they communicate with each other through socket,both of them open a server socket ,the port is special and dedicated to each other,no other client use it. under such situation,i think keeping the socket connection opening is a good solution,it is not necessay to close it at end of each communication and reopen it at the beginning of next communication,because the opening and closing the socket frequently will make the performance a bit lower. what is your opinion?
After two processes are through talking, the socket should be closed. If they need to talk off and on for six hours, then there's nothing wrong with having a socket open for six hours. Not sure where you got the idea that a socket should be closed after each short exchange of information.
my project is 7x24 system,the two subsystem communicate each other RANDOMLY,both of them don't know when they need exchange information.at every communication,the message is very short.for example: now sysA send a short message to sysB,then free,that mean this session has finished,the next message may be in two seconds or two hours later,the direction may be from sysA to sysB or reverse,no body know,i mean that in the free period,can i keep the socket opening? in fact,in my program,i never close the socket connection,as soon as the two systems start up,they connect together.
Originally posted by Ernest Friedman-Hill: After two processes are through talking, the socket should be closed. If they need to talk off and on for six hours, then there's nothing wrong with having a socket open for six hours..........
it is not request-response procedure,is only short message,and needn't wait for answer,so that,after sending the message,i think the talking is finished,as you said,i should close the socket,but the next message may be coming soon,i need to reopen the socket.thus the socket is opened and closed frequently,who don't we keep it opening forever? [ May 08, 2004: Message edited by: zb cong ] [ May 08, 2004: Message edited by: zb cong ]
If you choose not to close and re-open for every message, consider closing and reopening at least once after any failure. It could be the remote server process has been restarted and the connection you held is no longer valid. One way to look at this would be to prove that closing and reopening is a problem. Do you have test cases and metrics to show there is an issue? You might have reasons other than performance to hold them open, so even this wouldn't give a complete answer - your judgement still rules.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi