socket scripts added

This commit is contained in:
Mari Wahl 2014-12-16 12:58:22 -05:00
parent d01824f424
commit ac171e1195
5 changed files with 159 additions and 7 deletions

View file

@ -4,3 +4,31 @@ __author__ = "bt3"
import socket
# Defining constants
HOST = 'localhost'
PORT = 9090
DATA = 'GET / HTTP/1.1\r\nHost: google.com\r\n\r\n'
def tcp_client():
# Create a socket object
# AF_INET parameter: to use standard IPv4 address
# SOCK_STREAM: to indicate tcp client
client = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
# Connect the client
client.connect(( HOST, PORT ))
# Send data
client.send(DATA)
# Receive some data
response = client.recv(4096)
print response
if __name__ == '__main__':
tcp_client()