Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Socket connection

 
Binesh Veetil
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to open multiple socket connection to different IPs, which I will be doing it in a 'for' loop. Is it a best practice to create a new Socket object within the for loop? Or is it fine if I create a new Socket object before the for loop, use it for multiple connections and subsequently close it after the for loop.

Thanks.
 
Tim Moores
Bartender
Posts: 2686
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you go about changing the host/IP a socket is connected to after it has been created?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binesh Veetil wrote:Hi,

I need to open multiple socket connection to different IPs, which I will be doing it in a 'for' loop. Is it a best practice to create a new Socket object within the for loop? Or is it fine if I create a new Socket object before the for loop, use it for multiple connections and subsequently close it after the for loop.

Thanks.


You cannot use a Socket for multiple connections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic