本文整理汇总了Python中server.Server.send方法的典型用法代码示例。如果您正苦于以下问题:Python Server.send方法的具体用法?Python Server.send怎么用?Python Server.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.send方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Shell
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import send [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"]
示例2: Searcher
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import send [as 别名]
#.........这里部分代码省略.........
self.is_search_updated = True
def exclude_word(self, word):
"""Block tweets containing the given word."""
with self.lock:
if word not in self.excluded_words:
self.excluded_words.append(word)
self.is_search_updated = True
def remove_excluded_word(self, word):
"""Stop blocking the given word."""
with self.lock:
if word in self.excluded_words:
self.excluded_words.remove(word)
self.is_search_updated = True
def exclude_user(self, user):
"""Block tweets from the given user."""
with self.lock:
if user not in self.excluded_users:
self.excluded_users.append(user)
self.is_search_updated = True
def remove_excluded_user(self, user):
"""Stop blocking the given user."""
with self.lock:
if user in self.excluded_users:
self.excluded_users.remove(user)
self.is_search_updated = True
def run(self):
"""
Search Twitter, process the results, and
send data to the clients, over and over. Shut down
Tweeteor when it is told to exit (e.g. by the Controller).
"""
screen = pygame.Surface(SCR_SIZE)
self.server.start()
tweet_positions = dict()
try:
while not self.exit.is_set():
if self.is_search_updated:
# This ensures that all tweets match the current search,
# and are not just leftovers from a previous one.
self.tweets.clear()
self.is_search_updated = False
search = self.get_search()
# Twitter returns an error for empty searches,
# so this is a way around it
if search != '':
# Check twitter API for all parameters
params = {'q': search,
'result_type': 'recent',
'lang': 'en',
'count': 100}
r = requests.get(
'https://api.twitter.com/1.1/search/tweets.json',
headers=self.headers,
params=params)
if 'statuses' in r.json():
tweets = [tweet for tweet in safesearch.safe_filter(r.json()['statuses']) if 'retweeted_status' not in tweet]
else:
print r.json()
continue
for tweet in tweets:
if tweet['id'] in self.tweets:
示例3: int
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import send [as 别名]
if not configs:
logging.warning('no config file found, using default settings')
port = 5678
mode = 'both'
else:
port = int(parser.get('general','port'))
mode = parser.get('general','mode')
if mode == 'both' or mode == 'server':
# start server
server = Server(port)
server.start()
logging.info('started server at port '+str(port))
if mode == 'both' or mode == 'client':
# start client
serverIP = parser.get('client','server')
client = Client(port)
logging.info('started client at port '+str(port))
client.connect(serverIP)
if mode == 'both' or mode == 'server':
while True:
msg = Pipe.read()
server.send(msg)
else:
# wait for kill signal
signal.pause()
示例4: main
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import send [as 别名]
def main():
broken = 0
kill_event = Event()
socket_server = Server()
socket_server.start()
gui = Gui(kill_event)
gui.start()
gui.set_status_server(True)
# =========================================
# Main Loop
# =========================================
game_open = False
game_started = False
last_results = None
kill_spree = (0,0)
while not kill_event.is_set():
sleep(0.1)
windows = get_windows_bytitle('League of Legends')
# =========================================
# Found Window
# =========================================
if windows:
if not game_open:
game_open = True
socket_server.send({ 'event': 'game_loading' })
gui.set_status_game(True)
window = windows[0]
# =========================================
# Screenshot
# =========================================
try:
screenshot = Screenshot(screenshot_image(window))
except:
#TODO: save screenshot
gui.set_status_stats(False)
gui.set_status_game(False)
gui.set_stats({})
continue
# =========================================
# Stats
# =========================================
try:
results = get_stats(screenshot)
except:
#TODO: save screenshot
results = None
if results is None:
gui.set_status_stats(False)
gui.set_stats({})
continue
# =========================================
# Stats Exist!
# =========================================
if not game_started:
game_started = True
socket_server.send({ 'event': 'game_started' })
gui.set_status_stats(True)
gui.set_stats(results)
if results['team_kills'] > 200 or results['team_deaths'] > 200 or results['kills'] > 200:
broken += 1
screenshot.image.save('broken{}.bmp'.format(broken))
# =========================================
# Events
# =========================================
if last_results and results:
diff_cs = results['CS'] - last_results['CS']
diff_kills = results['kills'] - last_results['kills']
diff_deaths = results['deaths'] - last_results['deaths']
diff_team_kills = results['team_kills'] - last_results['team_kills']
diff_team_deaths = results['team_deaths'] - last_results['team_deaths']
if diff_team_kills < 0 or diff_team_deaths < 0 or diff_kills < 0:
broken += 1
screenshot.image.save('broken_before_{}.bmp'.format(broken))
last_screenshot.image.save('broken_after_{}.bmp'.format(broken))
if diff_cs > 0:
socket_server.send({ 'event': 'cs', 'amount': diff_cs, 'total': results['CS'] })
#.........这里部分代码省略.........