本文整理汇总了Python中server.Server.recv方法的典型用法代码示例。如果您正苦于以下问题:Python Server.recv方法的具体用法?Python Server.recv怎么用?Python Server.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.recv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_loop
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import recv [as 别名]
def main_loop(self):
exit_app = False
srv = Server()
while not exit_app:
self.lego = None
srv.accept()
while True:
data = srv.recv()
logging.info(data)
if not data:
del self.lego
break
elif data == 'start':
if not self.lego:
self.lego = Lego()
if self.lego.idle:
thread.start_new_thread(self.start_lego, ())
elif self.lego and data == 'stop':
self.lego.stop()
elif self.lego and data == 'reset':
self.lego.reset()
elif data == 'exit':
exit_app = True
del self.lego
break
srv.close()
示例2: Shell
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import recv [as 别名]
class Shell(Cmd):
mode_auto = True
cmdline = {}
def __init__(self, saddr):
#self._nbsr = NonBlockingStreamReader(sys.stdin)
self._server = Server(saddr)
Cmd.__init__(self)
def update(self):
time.sleep(0.01)
req = {}
# line = self._nbsr.readline()
# if line:
# req["sock"] = 0
# req["data"] = line
# self.process(req)
# else:
req = self._server.recv()
if req:
self.process(req)
def process(self, req):
sock = req['sock']
if sock not in self.cmdline:
self.cmdline[sock] = req['data']
else:
self.cmdline[sock] = self.cmdline[sock] + req['data']
cmdline = self.cmdline[sock]
tail = cmdline[-1]
if (tail != '\n') and (tail != '\r'):
self.mode_auto = False
return
del(self.cmdline[sock])
result = self.run(cmdline)
self.response(sock, result)
if not self.mode_auto:
self.response(sock, "> ")
def response(self, sock, result):
if result is None:
return
if not isinstance(result, basestring):
if self.mode_auto:
data = json.dumps(result)
else:
data = []
for key, val in result.items():
data.append("%s\t\t: %s\n\r"%(key, str(val)))
data = ''.join(data)
else:
data = result
req = {"sock": sock, "data": data}
if sock != 0:
self._server.send(req)
else:
print req["data"]