简体   繁体   中英

How do you go about making a reliable udp protocol based upon tcp?

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/

Java套接字是基于BSD API建模的,因此accept返回的套接字是完全连接的。

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM