Skip to content

Commit ec434b5

Browse files
authored
Update client.py
1 parent 3008f39 commit ec434b5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

client/client.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# chat_client.py
2-
31
import sys
42
import socket
53
import select
64
import os
75
import subprocess
6+
from data import *
7+
88

99
def chat_client():
1010
if(len(sys.argv) < 3) :
11-
print 'Usage : python chat_client.py hostname port'
11+
print('Usage : python chat_client.py hostname port')
1212
sys.exit()
1313

1414
host = sys.argv[1]
@@ -21,11 +21,11 @@ def chat_client():
2121
try :
2222
s.connect((host, port))
2323
except :
24-
print 'Unable to connect'
24+
print('Unable to connect')
2525
sys.exit()
2626

2727
print 'Connected to remote host. You can start sending messages'
28-
sys.stdout.write('[Me] '); sys.stdout.flush()
28+
# sys.stdout.write('[Me] '); sys.stdout.flush()
2929

3030
while 1:
3131
socket_list = [sys.stdin, s]
@@ -38,18 +38,25 @@ def chat_client():
3838
# incoming message from remote server, s
3939
data = sock.recv(4096)
4040
if not data :
41-
print '\nDisconnected from chat server'
41+
print('\nDisconnected from server')
4242
sys.exit()
43-
else :
43+
else:
4444
#print data
45-
sys.stdout.write(data)
46-
sys.stdout.write('[Me] '); sys.stdout.flush()
47-
45+
# sys.stdout.write(data)
46+
try:
47+
if data.split()[2][0] == "!":
48+
command = data.split()[2][1:]
49+
value = getValue(command)
50+
s.send(str(value))
51+
#print(str(value))
52+
# sys.stdout.write('[Me] '); sys.stdout.flush()
53+
except:
54+
pass
4855
else :
4956
# user entered a message
5057
msg = sys.stdin.readline()
51-
veri=subprocess.check_output(['date'])
52-
msg += str(veri)
58+
#veri=subprocess.check_output(['date'])
59+
msg += str(msg)
5360
s.send(msg)
5461
sys.stdout.write('[Me] '); sys.stdout.flush()
5562

0 commit comments

Comments
 (0)