[python]Simple tcp client

So here’s the simple code:

import socket

host = ''
port = 8080
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.send(b'GET / HTTP/1.1\r\nHost:\r\n\r\n')
response = client.recv(4096)

So first create an object client, the attributes are IPV4 (socket.AF_INET) and tcp (socket.SOCK_STREAM).

Use the send method to send http request, must send the msg in bytes, hence the b.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s