Hands-On

Cards (2)

  • Python 'Socket' Module
    • This module exposes all of the necessary pieces to quickly write Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) clients and servers, use raw sockets, and so forth
  • Python 'Socket' Module
    • We first create a socket object with the AF_INET and SOCK_STREAM parameters 1. The AF_INET parameter indicates we’ll use a standard IPv4 address or hostname, and SOCK_STREAM indicates that this will be a TCP client
    • We then connect the client to the server 2 and send it some data as bytes 3. The last step is to receive some data back and print out the response 4 and then close the socket. This is the simplest form of a TCP client, but it’s the one you’ll write most often.