So I'm trying to have 2 players on a LAN find each other so that they can play a LAN game together. So I am broadcasting UDP, but I'm going around in circles trying to make it reliable. Sorry if my logic is a little confusing, let me know if something isn't clear. It's not 100% clear to me, hence the question. I'm sort of new to network programming, so I think I'm just missing something basic.
My algorithm that I have come up with is something like:
When a network game is started, continuously broadcast a search message at a regular interval. the search message contains the IP address of the sender.
At the same time listen for the opponents search broadcast.
Also listen for the opponents ACK message.
When a search broadcast is received, send ACK messages until an ACK-ACK is received.
When I receive a ACK message, I can stop the search broadcast and send back an ACK-ACK.
Now my problem is how do I know when the opponent has received the ACK-ACK? The opponent can't stop sending ACKs until they receive the ACK-ACK, since they don't know if I've gotten the ACK yet. Obviously making a chain of ACK-ACK-ACK-... messages isn't going to work. If I am just on a Lan, everything should be pretty reliable, so should I just send 2 or 3 ACK-ACK messages a little spaced out, sleep for a second before I start the game, and assume that they got them, and just fail when I get a socket error later or something?
I think I'm just going to change my code to broadcast a UDP search message and send and listen for a TCP ACK. This way my problem is kind of solved. But really I'm just curious as to why I can't seem to figure out reliable UDP.