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:
- http://www.scottklement.com/rpg/socktut/bindapi.html
精彩评论