-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
47 lines (33 loc) · 1.52 KB
/
Copy pathclient.py
File metadata and controls
47 lines (33 loc) · 1.52 KB
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
42
43
44
45
46
47
import socket
import threading
import sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 1234
print("-----------------------------MULTICLIENT CHAT SERVER SYSTEM-------------------------------------------\n-----------------------------ENTER THE CREDENTIALS TO CONNECT TO CHAT SERVER--------------------------")
ip = input(' ENTER THE IP ADDRESS OF THE TO WHICH YOU WANT TO CONNECT\n IP ADDRESS:')
uname = input(" PLEASE ENTER THE USERNAME WHICH WILL DISPLAYED THROUGHOUT CHATTING\n USERNAME:")
try:
s.connect((ip, port))
except:print("\n\t OOPS LOGIN ERROR ...PLEASE PROVIDE VALID IP ADDRESS OF SERVER\n")
try:
s.send(uname.encode('ascii'))
clientRunning = True
def receiveMsg(sock):
serverDown = False
while clientRunning and (not serverDown):
try:
msg = sock.recv(1024).decode('ascii')
print(msg)
except:
print('OOPS.........SERVER IS NOW STOPPED....PLEASES HIT ANY BUTTON TO LEAVE THIS APPLCATION.......')
serverDown = True
threading.Thread(target = receiveMsg, args = (s,)).start()
while clientRunning:
tempMsg = input()
msg = uname + ' :::>>>' + tempMsg
if '#exitapp' in msg:
clientRunning = False
s.send('#exitapp'.encode('ascii'))
else:
s.send(msg.encode('ascii'))
except:print("\n\t OOPS ERROR\n")