Multiple sockets, same port

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Multiple sockets, same port

3,950 次查看
tobiasplayer
Contributor I
Hi,
 
  What is the proper method for opening several passive sockets listening on the same port with the mini-sockets API. Do I start one listen socket and try to spawn the connections from that or do I need to open a different listen socket for every connection I wish to allow?
 
Thanks,
Bob
标签 (1)
0 项奖励
回复
2 回复数

987 次查看
mjbcswitzerland
Specialist V
Hi Bob

Essentially it is only possible to have one listener on a particulat port.

Generally the listener then checks the source port to see whether there is already a connection. If not, it needs to 'create' a new connection (probably spawn in your terminology) to which it assigns the source port as reference.
Further frames to the particular open connection are then handled by the session (thread or whatever) assigned to the source port.
When the connection terminates, the connection resources can be freed.

The system must be dimensioned to be able to handle the expected number of parallel connections expected to be encountered. If a new connection is not possible since the connection limit has been reached the connection can be refused by sending a RST.

Regards

0 项奖励
回复

987 次查看
tobiasplayer
Contributor I
Thanks Mark!
 
   I pretty much got through it by the end of the day yesterday, but you have confirmed what I did. I have done this kind of thing many times using standard Berkeley sockets, but between their added twist of having to use a callback routine for everything and and the examples using their "msring" ring buffer code, I was thoroughly confused.I needed more control over the buffer assignments so I ended writing a special version of some of the msring functions and then took more control in my app.
 
Bob
0 项奖励
回复