Home > Software engineering >  UDP how a client receives data from multiple servers at the same time?
UDP how a client receives data from multiple servers at the same time?

Time:09-17

I wrote the program of an asynchronous communication UDP, PC as the client, to receive data from multiple servers at the same time, using FD_READ WSAAsyncSelect judgment, and then call yourself on the receiving function
Now my question is, how to determine the received data is which server? How do you write call RecvFrom function?

CodePudding user response:

The client didn't receive much server functions,
But you can open multiple ports link different servers,
Port of the server would be fixed,

CodePudding user response:

Int recvfrom (
_In_ SOCKET s,
_Out_ char * buf,
_In_ int len,
_In_ int flags,
_Out_ struct sockaddr * from,
_Inout_opt_ int * fromlen

);
The from it contains send the IP address

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740120 (v vs. 85). Aspx

CodePudding user response:

CodePudding user response:

Use of multiple processes,

CodePudding user response:

Received will be returned to the sender IP, if cannot be judged through the IP, can add logo in the data transmission

CodePudding user response:

The client to connect to the server, will be assigned a socket descriptor, then each receives a packet, the socket descriptor in the callback function together as a parameter can be identified

CodePudding user response:

CodePudding user response:

CodePudding user response:

Recvfrom a parameter is the source address, so distinguish server,

CodePudding user response:

Not UDP client and server runs, by receiving package the address of the judgment
  • Related