Skip to content

Commit 8dce9d6

Browse files
committed
add TCP client
Resolves: Related: Signed-off-by: Daniel Andrei Minca <mandrei17@gmail.com>
1 parent 189d980 commit 8dce9d6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tcp_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python2
2+
# SIMPLE TCP CLIENT
3+
4+
import socket
5+
6+
host = 'www.google.com'
7+
port = 80
8+
9+
# create socket obj
10+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11+
12+
# connect
13+
client.connect((host, port))
14+
15+
# send data
16+
client.send("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
17+
18+
# receive data
19+
response = client.recv(4096)
20+
21+
print response
22+

0 commit comments

Comments
 (0)