I am learning about sockets in Python and came up with
variable = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
I understood the function of this socket.socket
and socket.AF_INET
but I am curious about socket.SOCK_STREAM
. What is its function?
In the Internet domain, the SOCK_STREAM socket type is implemented on the Transmission Control Protocol/Internet Protocol (TCP/IP) protocol. A stream socket provides for the bidirectional, reliable, sequenced, and unduplicated flow of data without record boundaries.
SOCK_STREAM means that it is a TCP socket. SOCK_DGRAM means that it is a UDP socket. These are used 99% of the time. There are other possibilities as well, see https://docs.python.org/2/library/socket.html#socket.SOCK_STREAM (you will have to google for the meaning of each one).
SOCK_DGRAM : Provides datagrams, which are connectionless messages of a fixed maximum length. This type of socket is generally used for short messages, such as a name server or time server, because the order and reliability of message delivery is not guaranteed.
s = socket(AF_INET, SOCK_STREAM, 0); This call results in a stream socket with the TCP protocol providing the underlying communication. The following creates a datagram socket for intramachine use: s = socket(AF_UNIX, SOCK_DGRAM, 0); Use the default protocol (the protocol argument is 0) in most situations.
SOCK_STREAM
means that it is a TCP socket.
SOCK_DGRAM
means that it is a UDP socket.
These are used 99% of the time. There are other possibilities as well, see https://docs.python.org/2/library/socket.html#socket.SOCK_STREAM (you will have to google for the meaning of each one).
SOCK_STREAM
is a constant indicating the type of socket (TCP), as opposed to SOCK_DGRAM
(UDP).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With