Computer Forums

Computer Forums (http://www.computerforums.org/forums/)
-   Networking | DNS (http://www.computerforums.org/forums/networking-dns/)
-   -   several TCP sockets (http://www.computerforums.org/forums/networking-dns/several-tcp-sockets-213521.html)

m4l490n 10-09-2011 06:42 PM

several TCP sockets
 
hi everybody

can I have several sockets using the same port in a computer (acting this as server)? Or Do I have to use one different port for every socket that I need?

root 10-10-2011 10:28 AM

Re: several TCP sockets
 
generally you can't have two processes listening on the same port.

but you can have one process listening on a port that spawns multiple sockets. e.g. you generally start a process with only a few sockets, and spawn more sockets as the connection count goes up. after clients have finished talking to the server process you kill the sockets to keep resource use down.

I assume that you're writing some software? -if you're bothered about the socket connections

m4l490n 10-10-2011 06:43 PM

Re: several TCP sockets
 
Quote:

Originally Posted by root (Post 1099931)
generally you can't have two processes listening on the same port.

but you can have one process listening on a port that spawns multiple sockets. e.g. you generally start a process with only a few sockets, and spawn more sockets as the connection count goes up. after clients have finished talking to the server process you kill the sockets to keep resource use down.

I assume that you're writing some software? -if you're bothered about the socket connections

Yes, well not directly, but I don't know what would be more efficient, to have multiple sockets opened at the same port or to have one individual port for every client

root 10-11-2011 07:32 AM

Re: several TCP sockets
 
multiple sockets.

think of it this way.

The queue length on the TCP stack is constant, having more ports isn't going to mean you can accept more waiting connections. (e.g. there isn't a separate queue for each port, nor each socket). so you gain no benefit on this.

when you say efficiency, efficiency of what?
a single process could listen on hundreds of ports,
this is not efficient use of ports,

and since one one program can listen on a given port at any given time, it might lead you into trouble.
if for example you listen on ports 50 - 150, then you can't run a web server on the machine alongside your existing application as you're already using port 80. either the web server won't be able to bind to the port because your program started first, or your program won't be able to bind to the port because the web server is already using it.

it won't really make a difference to the CPU or memory load though.

if you assign a single socket to each port, you've got 100 open sockets,
if you use 1 port and assign 100 sockets to the port, you've got 100 open sockets.


All times are GMT -5. The time now is 02:53 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0