0
votes

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?

3
@Seth Carnegie I'm actually using qt, but I'm studying the way java did it. Qt is similar, it uses a socket descriptor. I'm more curious as to at what point in the tcp packet exchange does it return a socket?carboncomputed

3 Answers

2
votes

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/

0
votes

Java sockets are modeled upon the BSD API, so the socket returned by accept is supossed to be fully connected.

0
votes

Firstly to answer the question - when accept returns the socket is connected.

Secondly the best way of doing anything like this is to use ØMQ because it is so amazing and does so very much for you.

Finally taking from this article, it works like this:

The User Datagram Protocol (UDP) is one of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol (IP) network without requiring prior communications to set up special transmission channels or data paths.

enter image description here