26

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?

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Shashank Pulijala
  • 361
  • 1
  • 3
  • 3

3 Answers3

45

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).

freakish
  • 54,167
  • 9
  • 132
  • 169
  • 2
    Is there a reason why they didn't just name it SOCK_TCP and SOCK_UDP? – Rockstar5645 Mar 09 '20 at 22:17
  • 1
    @Rockstar5645 generally tcp/udp is sock_stream/dgram over ip4/6. But sock_stream/dgram can mean other things, see this, third answer: https://stackoverflow.com/questions/5815675/what-is-sock-dgram-and-sock-stream/10810040 But typically, like 99% of time it will be tcp/udp. – freakish Mar 09 '20 at 22:56
9

SOCK_STREAM is a constant indicating the type of socket (TCP), as opposed to SOCK_DGRAM (UDP).

shafeen
  • 2,431
  • 18
  • 23
5

The SOCK_STREAM means connection-oriented TCP protocol.

Abhish
  • 67
  • 2
  • 5