-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
executable file
·32 lines (28 loc) · 782 Bytes
/
client.py
File metadata and controls
executable file
·32 lines (28 loc) · 782 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
#!/usr/bin/python2.7
import socket
def main():
while(1):
name = raw_input("your nickname: ")
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server,port = raw_input("server:port : ").split(":")
if((server is '') | (not port.isdigit())):
print "Error: Please enter valid server and port"
continue
try:
sock.connect((server,int(port)))
sock.send("NICKNAME:"+name)
except socket.error, err:
print ("Could not connect to {}:{}\n{} ".format(server,port,err))
continue
while(1):
data = raw_input("enter message: ")
sock.send("DATA:"+data)
if(data == "/dc"):
print "disconnected from ", server
sock.close()
break;
elif(data == "/exit"):
sock.close()
exit(0)
if __name__=="__main__":
main()