I am attempting to write a reliable udp protocol, however I am confused as to when the server hands the connection over to a socket.
In java, a tcp server listens on a specific port then on accept, returns a socket.
Socket clientSocket = server.accept();
Does the accept method return a socket after the syn bit exchange or when the state is Established?
When accept method returns the socket, the socket is in connected state and SYN / SYN-ACK packets are exchanged before the accept method returns the socket. In fact the SYN packets are not exchanged in accept method. These packets are exchanged on the driver layer (TCP Stack).
If you are trying to write reliable UDP then I would strongly recommend you to have a look at UDT project source code. It is written in C++ but you can take lot of guidelines from this project. The UDT project is very well written, highly efficient and very stable.
http://udt.sourceforge.net/