Waroulolz
Waroulolz

Reputation: 307

Is it possible to make both TCP and UDP connections between two pieces of software

I'm currently developping a highly responsive game in python using client-server model. The speed of the data exchanges between the client and the server needs to be very fast.

Is it possible to make both, udp and tcp connections ? Udp would be used only during the game. And Tcp will be used for more reliability-needed messages like connection, name changes, chat,... Is it also a good way of thinking ? Or should i use only UDP ?

Upvotes: 2

Views: 220

Answers (3)

Andriy Tylychko
Andriy Tylychko

Reputation: 16256

You can also use a 3rd-party library that builds reliability layer over UDP and specify required reliability per packet. As an example you can check Raknet.

Upvotes: 0

usr
usr

Reputation: 171178

Yes, this can be a good idea. With UDP, a single lost packet does not stall the entire stream. On the other hand you need retry and congestion control.

I'd try to send messages using UDP and if no confirmation arrives within a short amount of time re-send them on a TCP connection that has been kept open. That should move 99% of the load to UDP and use TCP for congestion control and reliability.

The H2O database does it that way.

Upvotes: 1

Andrew Johnson
Andrew Johnson

Reputation: 3186

You can bind your UDP and TCP connections on different ports or even on the same port. As for which to use, it is up to you. Try both out and if TCP is too slow or UDP is too unreliable then you always have the option to switch.

Upvotes: 1

Related Questions