Skip to content

Instantly share code, notes, and snippets.

@mhtsai1010
Last active August 22, 2016 04:07
Show Gist options
  • Save mhtsai1010/7fcdcb644b102f07c909 to your computer and use it in GitHub Desktop.
Save mhtsai1010/7fcdcb644b102f07c909 to your computer and use it in GitHub Desktop.
Python: tcp client sockets
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
target_host = "127.0.0.1"
target_port = 80
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect the client
client.connect((target_host, target_port))
# send some data
client.send("input some data here")
# receive some data
response = client.recv(4096)
# print response
print response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment