Python’s socket module provides an
interface to the Berkeley sockets API.
The primary socket API functions and
methods in this module are:
socket()
bind()
listen()
accept()
connect()
connect_ex()
send()
recv()
close()
  TCP Sockets
Why should you use TCP? The Transmission Control
Protocol (TCP):
•Is reliable: packets dropped in the network are
detected and retransmitted by the sender.
•Has in-order data delivery: data is read by your
application in the order it was written by the sender.
               TCP Sockets
            Why should you use TCP? The Transmission Control
            Protocol (TCP):
            •Is reliable: packets dropped in the network are
            detected and retransmitted by the sender.
            •Has in-order data delivery: data is read by your
            application in the order it was written by the sender.
we’ll create a socket object using socket.socket() and specify the socket type as socket.SOCK_STREAM
  UDP Sockets
User Datagram Protocol (UDP) sockets created with
socket.SOCK_DGRAM aren’t reliable, and data read
by the receiver can be out-of-order from the
sender’s writes.
Why is this important?
Networks are a best-effort delivery system.
There’s no guarantee that your data will reach its
destination or that you’ll receive what’s been sent to
you.
sequence of
socket API
calls and data
flow for TCP