开发者

How to use a server with multiple IP address?

I have a server-process that listen to a specific port (say 60000), and my linux box has two ip-address (say ip1, and ip2).

Can I somehow start two processes in my linux box, such that Process1 can receive all packets sent t开发者_运维问答o ip1:60000 and Process2 can receive all packets sent to ip2:60000.

Thanks,


Yes. You'll want to use the bind system call on the listening socket that specifies the listening IP address, instead of the (more usual) INADDR_ANY. [Reference 1]

Then, use one IP address in one process, and one IP address in the second process. Both will be able to share the same listening port.


References:

  1. http://www.scottklement.com/rpg/socktut/bindapi.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜