原來的**
definput_command(self):
msg = raw_input('
\nplease input the command:')
remote_id = raw_input("
please input remote id:")
msg_send = "
%s||%s
" %(remote_id, msg)
self.client_socket.send(msg_send)
self.flag = 1
#todo 這裡輸入完畢後socket會關閉,找到原因後寫到上
defsocket_handler(self):
while 1:
if self.flag == 0:#
如果沒有輸入就等待輸入,否則等待網路返回
self.input_command()
rlist = [self.client_socket] #
接收列表
read_list, write_list, error_list = select.select(rlist, , , 2)
for sock in
read_list:
#incoming message from remote server
if sock ==self.client_socket:
data = sock.recv(4096)
ifnot
data:
'\ndisconnected from chat server
'sys.exit()
else
:
#print data
self.process_data_return(data)
self.prompt()
其實我也不太懂為什麼,把輸入放到select後邊就可以了
definput_command(self):
msg = raw_input('
\nplease input the command:')
remote_id = raw_input("
please input remote id:")
msg_send = "
%s||%s
" %(remote_id, msg)
self.client_socket.send(msg_send)
self.flag = 1
defsocket_handler(self):
f = open('
input.txt
','w+')
while 1:
start = datetime.datetime.now() #
開始時間
rlist = [self.client_socket] #
接收列表
read_list, write_list, error_list = select.select(rlist, , , 2)
if self.flag == 0: #
如果沒有輸入就等待輸入,否則等待網路返回
self.input_command()
for sock in
read_list:
time.sleep(0.2)
now =datetime.datetime.now()
if (now - start).seconds >timeout:
break
#watchddog
#incoming message from remote server
if sock ==self.client_socket:
data = sock.recv(4096)
ifnot
data:
'\ndisconnected from chat server
'sys.exit()
else
:
#print data
self.process_data_return(data)
self.prompt()
監聽socket例子
tcpserver.c include include include include include include include include include include includestatic bool stop false static void handle term int ...
socket連線監聽udp包
用的2010的vc 版本,設定很簡單,就是一般的設定,就可以監聽了。但主要說一些配置外的。這裡可能用自定義訊息,1 利用方法send message 控制代碼名,0,0 傳送訊息。新增控制代碼時,應先定義 define receive data wm user 100 注意後面的wm user 10...
windows 下socket 程式設計
111111windows 下用microsoft visual studio 2005 編寫socket程式 windows 下實現同步socket程式設計,和linux下有許多相同的地方,基本的socket流程完全相同,所有的socket 相關的函式都在 winsock.h 中宣告 還有wind...