-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
33 lines (30 loc) · 815 Bytes
/
client.py
File metadata and controls
33 lines (30 loc) · 815 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
import socket
import select
import sys,os
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if len(sys.argv) != 3:
print "Correct usage: script, IP address, port number"
IP_address=raw_input("Enter Server Ip: ")
Port=input("Enter port no: ")
#exit()
else:
IP_address = str(sys.argv[1])
Port = int(sys.argv[2])
server.connect((IP_address, Port))
while True:
sockets_list = [sys.stdin, server]
read_sockets,write_socket, error_socket = select.select(sockets_list,[],[])
for socks in read_sockets:
if socks == server:
message = socks.recv(2048)
print message
else:
message = sys.stdin.readline()
if message=="bye":
exit()
else:
server.send(message)
sys.stdout.write(str(socket.gethostname()+":-"))
sys.stdout.write(message)
sys.stdout.flush()
server.close()