本文整理汇总了Python中network.Network.recv方法的典型用法代码示例。如果您正苦于以下问题:Python Network.recv方法的具体用法?Python Network.recv怎么用?Python Network.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.recv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Webserver
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import recv [as 别名]
class Webserver(object):
def __init__(self):
cherrypy.engine.subscribe('stop', self.stop)
self.net = Network(WEBSERVER_IP, WEBSERVER_PORT)
# spusti se pri zapinani
def stop(self):
# spusti se pri vypinani
pass
@cherrypy.expose
def index(self):
# exposed metoda -- zavolali jsme /
return base.render()
def doit(self, action, value):
# spustit ledky
data = dict()
data["key"] = action
data["value"] = value
self.net.send(data, SERVER_IP, SERVER_PORT)
@cherrypy.expose
def set(self, value):
self.doit("set", value)
return self.index()
@cherrypy.expose
def get(self, value):
self.doit("get", value)
tmp = self.net.recv()
# should be recv
return tmp
示例2: Network
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import recv [as 别名]
from network import Network
from datetime import datetime
from modules import *
from config import *
import threading
net = Network(CLIENT_IP, CLIENT_PORT)
net.send({"key": "status", "value": "login"}, SERVER_IP, SERVER_PORT)
try:
while True:
x = ""
# receive data
data = net.recv()
# wrong data, try it again
if data == False:
continue
# variable HACK -- safe check
try:
cmd = data["cmd"]
except TypeError:
x = x + "CMD NOT FOUND"
continue
except KeyError:
x = x + "CMD NOT FOUND"
continue