March 2019
Beginner
490 pages
12h 40m
English
The following code is an example of a simple TCP client. If you look carefully, you can see that the following code will create a raw HTTP client that fetches a web page from a web server. It sends an HTTP GET request to pull the home page.
To create our connection, we need to import the socket module and use the connect method to pass the (HOST, PORT) tuple as a parameter. With the send method from the socket client object, we send the data for the request and get the response in the data object using the recv method.
You can find the following code in the socket_tcp_client.py file:
import socketHOST = 'www.yahoo.com'PORT = 80BUFSIZ = 4096ADDR = (HOST, PORT)if __name__ == '__main__': client_sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ...
Read now
Unlock full access