File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change 1- # chat_client.py
2-
31import sys
42import socket
53import select
64import os
75import subprocess
6+ from data import *
7+
88
99def 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 '\n Disconnected from chat server'
41+ print ( '\n Disconnected 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
You can’t perform that action at this time.
0 commit comments