0
votes

I want to know that if the socket is in a connected state with SOCK_STREAM transfer, does the packet sent between send() and recv() did reliable TCP protocol? Something like ACK and seq number for prevent the packet lost and correctness, or I need to implement the TCP protocol by myself?

Also,

If UDP without connect() with SOCK_DGRAM, does the packet sent between sendto() and recvfrom() did the UDP protocol? (ACK, seq number or timer...)

1
You can treat a SOCK_STREAM as a stream.David Schwartz

1 Answers

1
votes

You do not need to implement TCP or UDP yourself.

From man 2 socket:

SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams.

SOCK_DGRAM Supports datagrams (connectionless, unreliable messages of a fixed maximum length).

From man 7 tcp:

tcp_socket = socket(AF_INET, SOCK_STREAM, 0);

DESCRIPTION This is an implementation of the TCP protocol defined in RFC 793, RFC 1122 and RFC 2001 with the NewReno and SACK extensions.

From man 7 udp:

udp_socket = socket(AF_INET, SOCK_DGRAM, 0);

DESCRIPTION
This is an implementation of the User Datagram Protocol described in RFC 768.

Also see man 7 socket, man 2 send, and man 2 recv.

All referenced man pages are from the "Linux Programmer's Manual".