Is it safe to use a single UdpClient instance on two separate threads to simultaneously receive from a client and send to a different client? According to the MSDN docs this is fine for TcpClient but I'm unsure about it for UdpClient. I shortened my code here to get the idea across.
void ReceiveThread () {
while (running) {
var payload = udpClient.Receive(ref clientEndPoint);
QueuePayload(payload);
}
}
void SendThread () {
var payload = DequeuePayload();
while (running) {
udpClient.Send(payload, payload.Count, client2EndPoint);
}
}
Would a good solution to this problem be to create a new UdpClient whenever I send a payload? The payloads will be sent quite frequently though (around 20 per second).