954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Winsock listen on multiple ports

Can someone give me an example on how to listen on multiple ports with Winsock? I have been trying for hours with no luck..

osean
Newbie Poster
14 posts since Dec 2005
Reputation Points: 10
Solved Threads: 0
 

I haven't done it, but I dont think that it should be much different than listening in a single port...Just create SocketNumber1 and bind it to portnumber1, create SocketNumber2 and bind it to portnumber2, and listen on both sockets. Depending on the Socket I/O Model, you will get which request comes to which socket. Give what you have tried so far, and maybe someone will be able to see what you are doing wrong.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

Thanks for the reply,
I can do it easily using the method you described (create a socket for each individual port i want to listen on).. is there an easier way? i want to be able to listen on 15+ ports and that means i'm going to have to create an idividual socket for each port i want to listen on, so 15+ sockets.. it would be nice if i could just use one socket for listening on several ports.

osean
Newbie Poster
14 posts since Dec 2005
Reputation Points: 10
Solved Threads: 0
 

>it would be nice if i could just use one socket for listening on several ports.
Too bad it doesn't work that way. You have to have multiple sockets to listen on multiple ports, whether it be something like an array of sockets in the thread, or multiple threads that work with a single socket.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

I am not 100% sure about this, but I dont think you can do that. Maybe someone who has more experiance in network programming will disagree, but out of the Socket Models that I have used upto now, when you get a connection request, you can only tell to what socket is that request made. There is no way of differentiating from which port-number.

By the way, why do you need 15 different port numbers? That means you are trying to use 15 different protocols. What are you trying to do?

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

I was messing around with a client-server p2p application, I guess I will just go with the first method suggested (creating a socket for each port), thanks.

osean
Newbie Poster
14 posts since Dec 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You