TCP | UDP | |
---|---|---|
socket type | SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams. An out-of-band data transmission mechanism may be supported. | SOCK_DGRAM Supports datagrams (connectionless, unreliable messages of a fixed maximum length). |
connect() | √ | × |
TCP | UDP | |
---|---|---|
listen | √ listen() marks the socket referred to by sockfd as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept. | × |
accept | √ 该函数不会阻塞,需借助 while 检查连接是否建立。连接建立后,返回新的文件描述符;传入地址是客户端地址。 | × |