UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2012-04-03 09:15 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Using connect() with select()

Hi Guys!

Just a quick one, what is the best way to create and process multiple connect()'s at the same time? i.e using connect() with select() in a similar manner to combining listen() with select() and accept() as you would for example a chat server.

Looking forward to your reply.

Offline

#2 2012-04-04 01:08 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Using connect() with select()

Offline

#3 2012-04-05 01:05 AM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Using connect() with select()

Thanks Rob, that was pretty straight forward. results from netstat:

TCP    192.168.1.4:8552       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8553       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8554       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8555       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]

If i wanted to create multiple connect()'s to the same host but on separate ports, i.e (8000 - 8004) i presume its possible to leave the default port that was passed into getaddrinfo() for the first call to connect() and then, increment and forcible set the port for the remaining connects(). Correct ?

Creating multiple connect()'s to different hosts at the same time, i imagine you would use a similar approach to what you have kindly stated above, but with additional calls to getaddrinfo() for DNS lookup on the various addresses ? Unless there is a more efficient way ?

Last edited by RipRage (2012-04-05 01:28 AM)

Offline

#4 2012-04-05 01:14 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Using connect() with select()

Offline

#5 2012-04-05 03:06 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Using connect() with select()

That is great, thanks Rob.

One last question to finish this thread off.

What is the best way to listen() on multiple ports at the same time ?

Offline

#6 2012-04-05 08:45 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Using connect() with select()

Offline

#7 2012-04-05 09:17 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Using connect() with select()

Rob, your a star! Thank you for your time :-)

Offline

#8 2012-05-07 07:55 PM

HAMID
Guest

Re: Using connect() with select()

TCP    192.168.1.4:8552       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8553       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8554       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]
TCP    192.168.1.4:8555       64-191-13-3:http       ESTABLISHED
[Multi-Connect.exe]

#9 2012-05-08 12:33 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Using connect() with select()

Did you forget to add your own comment there, Hamid?

Offline

Board footer

Powered by FluxBB