## 说明
该脚本支持对套接字进行读写操作(而非简单的阻塞式应答服务)
用于充当服务器角色,向其发起心跳、根据需要返回指定的数据模拟等....
## 源码 ( s_ok.py )
import threading
import socket
import time
encoding = 'utf-8'
BUFSIZE = 1024
gCount = 0
class Writer(threading.Thread):
def __init__(self, client):
threading.Thread.__init__(self)
self.client = client
self.count = 0
def run(self):
while True:
data = self.readline()
if(data):
ret = bytes.decode(data, encoding)
print "=> Client: %s" % (ret)
self.client.send(ret)
else:
break
print "close:", self.client.getpeername()
def readline(self):
rec = raw_input("Input Msg:")
if rec:
string = rec
else:
string = &