예제 #1
0
            msg = app_socket.receive()
            msg_info = json.loads(msg)
            receiver = msg_info.get('to_user')
            receiver_socket = web_socket.get(receiver)
            receiver_socket.send(msg)
        except:
            pass


@ws.route('/toy/<toy_id>')
def toy(toy_id):
    toy_socket = request.environ.get('wsgi.websocket')  # type:WebSocket
    web_socket[toy_id] = toy_socket
    print('保持toy_socket连接。。。', toy_socket, toy_id)
    while True:
        try:
            msg = toy_socket.receive()
            msg_info = json.loads(msg)
            receiver = msg_info.get('to_user')
            receiver_socket = web_socket.get(receiver)
            receiver_socket.send(msg)
        except:
            pass


if __name__ == '__main__':
    http_server = WSGIServer(('0.0.0.0', 9528),
                             ws,
                             handler_class=WebSocketHandler)
    http_server.serve_forever()
예제 #2
0
@app.route('/query_range')
def query_range():
    parm = request.args.to_dict()
    processfilter = parm.get('processfilter')
    wildcard = ''
    if processfilter is not '':
        wildcard = re.sub(',', "','", "'" + processfilter + "'")
    log.warn(wildcard)
    start = parm.get('start')
    now = time.time()
    if start is None:
        start = now - 300
    end = parm.get('end')
    if end is None:
        end = now
    return DataProcessor.query(start, end, wildcard)


if __name__ == "__main__":
    scheduler_thread = threading.Thread(target=start, args=())
    scheduler_thread.setDaemon(True)
    scheduler_thread.start()
    log.info(u'Scheduler Started.')
    srv = WSGIServer(('0.0.0.0', 5000),
                     app,
                     handler_class=WebSocketHandler,
                     log=log)
    log.info(u'Started Server.')
    srv.serve_forever()
    shutdown()
예제 #3
0

# 私聊
@app.route("/o2o/<username>")
def o2o(username):
    user_socket = request.environ.get("wsgi.websocket")  # type: WebSocket
    if user_socket:
        userO2o_socket_dict[username] = user_socket

    while True:
        try:
            msg = user_socket.receive()
            msg_dict = json.loads(msg)

            to_user_link = msg_dict.get("toUser")
            from_user_link = msg_dict.get("fromUser")

            to_user_socket = userO2o_socket_dict.get(to_user_link)
            from_user_socket = userO2o_socket_dict.get(from_user_link)

            to_user_socket.send(msg)
            from_user_socket.send(msg)
        except:
            del userO2o_socket_dict[username]
            continue


if __name__ == "__main__":
    server = WSGIServer(("0.0.0.0", 8527), app, handler_class=WebSocketHandler)
    server.serve_forever()
예제 #4
0
def server_start():
    server = WSGIServer(('0.0.0.0', 5000),
                        app,
                        handler_class=WebSocketHandler,
                        log=log)
    server.serve_forever()