-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
41 lines (31 loc) · 841 Bytes
/
Copy pathclient.py
File metadata and controls
41 lines (31 loc) · 841 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
import socket, sys, select
def prompt():
sys.stdout.write('You: ')
sys.stdout.flush()
host = "127.0.0.1"
port = 31337
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
try:
sock.connect((host, port))
except:
print 'Something goes wrong'
sys.exit()
print 'Lets get started sending messages :)'
prompt()
while 1:
socket_list = [sys.stdin, sock]
read_sockets, write_sockets, error_sockets = select.select(socket_list, [], [])
for s in read_sockets:
if s == sock:
data = s.recv(4096)
if not data:
print '\nDisconnected'
sys.exit()
else:
sys.stdout.write(data)
prompt()
else:
msg = sys.stdin.readline()
sock.send(msg)
prompt()