forked from pcewebpython/echo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world_client.py
28 lines (24 loc) · 903 Bytes
/
hello_world_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import socket
# cd C:\Users\mimcdona\Dropbox\UW\UW-Python230_Project\echo-server\echo-server
# python hello_world_client.py
"""
hadron_socket = socket.getaddrinfo('hasthelargehadroncolliderdestroyedtheworldyet.com', 'http')
print(hadron_socket)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
client.connect(('216.92.96.71', 80))
msg = "GET / HTTP/1.1\r\n"
msg += "Host: hasthelargehadroncolliderdestroyedtheworldyet.com\r\n\r\n"
# You can only send bytes through a socket, never unicode:
msg = msg.encode('utf8')
print(msg)
client.sendall(msg)
response = client.recv(1028)
print(response)
# always manually clos sockets
client.close()
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
client_socket.connect(('127.0.0.1', 50002))
client_socket.sendall(b'Hello, world')
data = client_socket.recv(1024)
print('Received', repr(data))