Making UDP a connection-oriented protocol?

947 Views Asked by At

I made an online game that uses the UDP protocol to communicate between the clients and a server. However, since UDP is connection-less, I can't detect if a client closed the game or an error occurred in the network. Therefore, I need to make UDP a connection-oriented protocol, or at least detect network errors. How could I accomplish that? How is TCP connection oriented?

2

There are 2 best solutions below

3
Kev1n91 On BEST ANSWER

Firstly, I understand that you need UDP because of efficiency - but maybe you could try to give TCP a try?

Otherwise I would just do as @Phil Taprogge mentioned. Send a specific UDP package that gets identified by the server every n seconds. If the server does not recieve it for 3*n seconds it is very likely that the client has disconnected.

1
Phil Taprogge On

As you say, UDP has no concept of connections. So the only way to achieve what you want is to implement the required logic yourself on top of UDP.

You could, for example, have your clients 'check in' with the server regularly with a UDP packet containing a unique ID. If the server does not receive this from a client for some time, it would consider that client dead.