File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which more performant

 
zb cong
Ranch Hand
Posts: 416
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
zb cong
Ranch Hand
Posts: 416
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered java.net.DatagramSocket? Depending on you needs you can get by only with some sort of message count to avoid duplicates.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic