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?
Asked
Active
Viewed 854 times
1
-
If you need a connection change it to use TCP instead of UDP. – Don Roby Sep 04 '16 at 20:11
-
1I can't do this, I need speed. – None Sep 04 '16 at 20:12
-
Can't have both – OzieGamma Sep 04 '16 at 20:19
-
3Yes I can have both :D – None Sep 04 '16 at 20:25
2 Answers
2
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.

Phil Taprogge
- 96
- 6
1
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.

Kev1n91
- 3,553
- 8
- 46
- 96
-
1
-
Well maybe this comes from not good package sizes. Maybe if you collect the data and send one large TCP package instead of small TCP packages you could maybe increase the throughput. My next idea would be to make one TCP Connection and one UDP Connection. The TCP connection is simply for the purpose of knowing wether the client has disconnected. – Kev1n91 Sep 04 '16 at 20:22
-
1I like that idea. It would even add the ability to send TCP packets between computers. You gotta add this in your answer. – None Sep 04 '16 at 20:24