Skip to content

Commit 0d9569f

Browse files
authored
Update client.py
1 parent ec434b5 commit 0d9569f

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

client/client.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import sys
22
import socket
33
import select
4-
import os
5-
import subprocess
64
from data import *
75

86

9-
def chat_client():
10-
if(len(sys.argv) < 3) :
11-
print('Usage : python chat_client.py hostname port')
12-
sys.exit()
7+
def client():
138

14-
host = sys.argv[1]
15-
port = int(sys.argv[2])
9+
host = "192.168.131.129"
10+
port = int(9009)
1611

1712
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1813
s.settimeout(2)
@@ -24,42 +19,30 @@ def chat_client():
2419
print('Unable to connect')
2520
sys.exit()
2621

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

3025
while 1:
3126
socket_list = [sys.stdin, s]
32-
33-
# Get the list sockets which are readable
27+
3428
ready_to_read,ready_to_write,in_error = select.select(socket_list , [], [])
3529

3630
for sock in ready_to_read:
3731
if sock == s:
38-
# incoming message from remote server, s
3932
data = sock.recv(4096)
4033
if not data :
4134
print('\nDisconnected from server')
4235
sys.exit()
4336
else:
44-
#print data
45-
# sys.stdout.write(data)
37+
sys.stdout.write(data)
4638
try:
4739
if data.split()[2][0] == "!":
4840
command = data.split()[2][1:]
4941
value = getValue(command)
5042
s.send(str(value))
51-
#print(str(value))
52-
# sys.stdout.write('[Me] '); sys.stdout.flush()
5343
except:
5444
pass
55-
else :
56-
# user entered a message
57-
msg = sys.stdin.readline()
58-
#veri=subprocess.check_output(['date'])
59-
msg += str(msg)
60-
s.send(msg)
61-
sys.stdout.write('[Me] '); sys.stdout.flush()
6245

46+
6347
if __name__ == "__main__":
64-
65-
sys.exit(chat_client())
48+
sys.exit(client())

0 commit comments

Comments
 (0)