This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Multiple Socket connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Multiple Socket connection" Watch "Multiple Socket connection" New topic
Author

Multiple Socket connection

Binesh Veetil
Greenhorn

Joined: Jan 21, 2012
Posts: 9
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
How would you go about changing the host/IP a socket is connected to after it has been created?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Socket connection