Go Back   Computer Forums > General Computing > Networking | DNS
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 10-09-2011, 07:42 PM   #1
Solid State Member
 
Join Date: May 2011
Posts: 8
Question 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?
__________________

m4l490n is offline   Reply With Quote
Old 10-10-2011, 11:28 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default 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
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 10-10-2011, 07:43 PM   #3
Solid State Member
 
Join Date: May 2011
Posts: 8
Default Re: several TCP sockets

Quote:
Originally Posted by root View Post
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
m4l490n is offline   Reply With Quote
Old 10-11-2011, 08:32 AM   #4
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default 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.
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:25 AM.


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