admin管理员组

文章数量:1201569

I have 2 host that is part of one IP network 192.168.1.0/24. Let's say one of them is host A with IP address 192.168.1.1 and other host is B with IP address 192.168.1.2.

I have an application that generates UDP stream on host B and send it to 192.168.1.1:12345. Now I want to N separate processes running on host A to be able to receive this stream simultaneously. How can I do it?

I have 2 host that is part of one IP network 192.168.1.0/24. Let's say one of them is host A with IP address 192.168.1.1 and other host is B with IP address 192.168.1.2.

I have an application that generates UDP stream on host B and send it to 192.168.1.1:12345. Now I want to N separate processes running on host A to be able to receive this stream simultaneously. How can I do it?

Share Improve this question asked Jan 22 at 11:38 Kamil ZaripovKamil Zaripov 98012 silver badges39 bronze badges 1
  • You could write a program which creates the socket, binds it to the local address/port pair, and then fork new processes which reads from the socket and processes the messages. But please note that you don't have control over which process gets which message. And once a message is read, you can not put it back to be read by another process. Instead I suggest you have one program which receives all messages, and then distributes it to the actual processes that are supposed to process the data. Using local sockets (AF_LOCAL) you can use the normal socket API in the other processes. – Some programmer dude Commented Jan 22 at 11:47
Add a comment  | 

1 Answer 1

Reset to default 2

You can use multicast. Modify your application to send UDP packets to some multicast group address (e.g. 239.255.0.1:12). Any number of processes can subscribe to that group and receive the data. It might might require enabling IGMP on your network.

Other option is to use proxy.

本文标签: network programmingReceive one UDP stream with 2 applicationsStack Overflow