0

I'm working with .Net I'm looking to create a service and looking between TCP or UDP. Service is supposed to support multiple clients so I'm making it async with .Net SocketAsyncEventArgs as I've seen to have better performance and less memory compsumption. I know TCP is slower that UPD but I would like to know your opinion of what would work faster between this two scenarios

1) Using TCP and the SocketAsyncEventArgs, every client will connect and once the Service Accepts the connection basically every client has an endpoint to start sending and receiving, so multiple messages can be sent while the connection is open ( accepted). Basically every client has it's own connection and can have two way communication

2) Every client will send a UDP datagram to the same UDP server Endpoint so basically I have one endpoint for all clients to send all the messages then process them and send a datagram back to each individually.

Maybe I have a miss conception of TCP/UPD but basically the question is once I have an open TCP connection per client, is it slower that sending back and forth UDP messages when all clients are sharing the same initial UDP endpoint.

jmayor
  • 2,725
  • 4
  • 29
  • 37
  • 1
    It's impossible to answer this question without understanding what your application is going to do. If you're sending something that can tolerate lost packets (such as video streaming), UDP is potentially fine. If you're sending something that can't tolerate lost packets, UDP is not a suitable choice. – Daniel Mann Apr 19 '19 at 19:10

1 Answers1

0

Your first consideration should not be performance. TCP is a reliable protocol, UDP is not. If you implement UDP then you will need to implement additional logic to ensure messages reached their destination.

UDP makes sense in a couple of limited scenarios: (1) when you want to broadcast messages (TCP is not capable of broadcast) or (2) when you don't really care whether 100% of messages get to their destination.

AQuirky
  • 4,691
  • 2
  • 32
  • 51
  • I know about those rules, basically my question is with a TCP esablished connection Sending and receiving a few customers at a time, how slower does it perform vs UPD having to receive the packages from all the clients under the same port. – jmayor Apr 19 '19 at 18:44