• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket open/close

 
Richard Robbins
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing an application in which I have a thread that continuously monitors a queue (implemented as one of a vector, JMS queue, MSMQ, IBM MQSeries, etc.) for messages. When it finds a message, it sends it across a socket connection to another host machine. I am wondering whether there is an easy method to keep the socket open for a specified period of time while checking for a message. If the thread hasn't found a message within a specified time frame, the socket connection would then be closed. Is this possible with the Socket and ServerSocket classes only, or is there something else I need to involve? This issue results from the overhead involved with opening and closing sockets.
 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Both the Socket and SocketServer classes have a method called setSoTimeout(int timeout). The default time is 0, which means keep the socket open infinitely. The time specified is in milliseconds, so you will need to make sure that you multiply the number of seconds you want it to listen by 1000. Hope this is what you were looking for. Good luck!
Cheers,
RL
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!