0

Can I receive data from network by some processes simultaneously?

For instance, I have two computes in the LAN. One computer send udp packet to other computer on port 5200. In computer number two I want to receive this packet by two processes. Can I create two sockets on same ip and port?

I forget to say that Process A I can't modify. In other words, I want to create application that receive same data as Process A. (Proccess A and Proccess B locate on the computer number two that receive data)

Oleg Gopkolov
  • 1,684
  • 10
  • 17

2 Answers2

2

Yes! You can. Open the socket and set setsockopt with REUSE_PORT and REUSE_ADDRESS.

Uli Gue
  • 21
  • 2
1

How about you create process A to act as middleware between the two processes B and C. And then add extra data to the packets sent to process A which will be used to determine the final destination of the data - process B or process C.

EDIT: To answer your question exactly "no", for TCP/IP

"You can only have one application listening on a single port at one time."

Actually you question has been asked by someone else before, and I have only just cited the answer. The full answer can be found -> here.

Community
  • 1
  • 1
Igwe Kalu
  • 14,286
  • 2
  • 29
  • 39