当前位置: 首页>>代码示例>>Python>>正文


Python SocketIO.on方法代码示例

本文整理汇总了Python中socketIO_client.SocketIO.on方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIO.on方法的具体用法?Python SocketIO.on怎么用?Python SocketIO.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socketIO_client.SocketIO的用法示例。


在下文中一共展示了SocketIO.on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_data

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def send_data(save_path):
    """
    Sends all the data files that are present in the specified path to the Qbike server.
    :param save_path: Requires the path in which the trips are saved.
    :return: Nothing. The data is sent to the Server and the txt files are removed from the path's directory.
    """
    end = False
    Trip_nb = 100
    while end == False:
        if not os.path.isfile('C:\Users\Joren\Documents\Ir 1B\P&O\P&O 3\Tryouts\Trips\Trip1.txt'):
            end = True

        else:
            for nb in reversed(range(0, 100)):
                Trip = os.path.join(save_path, "Trip" + str(nb) + ".txt")
                Trip_nb = str(nb)
                if os.path.isfile(Trip):
                    break

            Trip_path = os.path.join(save_path, r"Trip" + Trip_nb + r".txt")

            with open(Trip_path, "r") as Trip:
                batch = json.load(Trip)

            info = {'purpose': 'batch-sender', 'groupID': "cwa2", 'userID': ID}
            socketIO = SocketIO('dali.cs.kuleuven.be', 8080)
            socketIO.on('server_message', on_response)
            socketIO.emit('start', json.dumps(info), on_response)
            socketIO.wait(2)
            socketIO.emit('batch-tripdata', json.dumps(batch), on_response)
            socketIO.wait(5)

            os.remove(Trip_path)

    print "Sent Data"
开发者ID:bicyclus,项目名称:prototype1,代码行数:37,代码来源:batch_wmusic.py

示例2: main

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def main(argv):
    (roombaPort, launcherPort, production) = parse_args(argv)

    global launcher_port
    launcher_port = launcherPort
    print("launcher on port %s" % launcher_port)
    global roomba_port
    roomba_port = roombaPort
    print("roomba on port %s" % roomba_port)

    global roomba # define roomba as unscoped global variable
    global launcher # define launcher as unscoped global variable
    try:
        roomba = Serial(port = roombaPort, baudrate = const.ROOMBA_BAUD_RATE) # open serial connection to roomba
    except SerialException:
        print('Serial connection to Roomba over %s could not be established' % roombaPort)
        sys.exit(-1)

    try:
        launcher = Serial(port = launcherPort, baudrate = const.LAUNCHER_BAUD_RATE, writeTimeout = None) # open serial connection to launcher
    except SerialException:
        print('Serial connection to launcher over %s could not be established' % launcherPort)
        sys.exit(-1)

    roomba.write(const.SEQ_START) # start
    time.sleep(1)
    roomba.write(const.SEQ_MODE_SAFE) # enter safe mode
    time.sleep(0.2)

    socketIO = SocketIO(const.PROD_SERVER_HOST, const.PROD_SERVER_PORT, CommandControl, verify = False) if production else SocketIO(const.DEV_SERVER_HOST, const.DEV_SERVER_PORT, CommandControl)
    
    socketIO.on('command', on_command)
    socketIO.on('client-disconnect', on_client_disconnect)
    socketIO.wait()
开发者ID:hashtag-include,项目名称:tanks-irl-device,代码行数:36,代码来源:client.py

示例3: main

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def main():
    app = App(False)
    socketIO = SocketIO(API_URL, 443, LoggingNamespace)
    socketIO.on('location', app.on_ws_location)

    Thread(target=socketIO.wait).start()
    app.MainLoop()
开发者ID:Proj-P,项目名称:project-p-systray,代码行数:9,代码来源:main.py

示例4: main

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def main(sip,port):
    global SERVER_IP
    global SERVER_PORT
    global SERVER_ADDR
    global socketIO
    global machine



    SERVER_IP = sip
    SERVER_PORT = port
    SERVER_ADDR = SERVER_IP + ":" + str(SERVER_PORT)
    socketIO = SocketIO(SERVER_IP, SERVER_PORT, LoggingNamespace)

    enter_nick()
    machine = sm("Test")
    signal.signal(signal.SIGINT, exit_match)

    

    socketIO.on(cs.JOIN_MATCH, machine.sock_onjoin_match)
    socketIO.on(cs.NEW_MATCH, machine.sock_match_confirm)
    socketIO.on(cs.BEGIN_MATCH, machine.sock_begin_match)
    socketIO.on(cs.RESULT, machine.sock_onresult)
    socketIO.on(cs.REMATCH, machine.sock_onrematch)
    socketIO.on(cs.LEAVE, machine.sock_onleave)

    socketIO.wait()
开发者ID:prudhvid,项目名称:rock-paper,代码行数:30,代码来源:client.py

示例5: login

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def login():
    image_response = fetch('https://livechan.net/captcha.jpg')
    image_data = image_response.read()

    with open('captcha.jpg', 'w') as f:
        f.write(image_data)
    os.system("open captcha.jpg")

    digits = int(raw_input("enter the captcha: "))
    post_params = {}
    post_params["digits"] = digits
    login_response = post('https://livechan.net/login', post_params)
    login_html = login_response.read()

    print login_html
    livechan_pass = get_password()
    if livechan_pass == "":
        login()

    global socketIO
    socketIO = SocketIO('https://livechan.net',
        cookies={'password_livechan': livechan_pass})
    socketIO.on('chat', on_chat)
    socketIO.on('user_count', on_user_count)
    thread.start_new_thread ( socketIO.wait, () )
开发者ID:emgram769,项目名称:livechan-tui,代码行数:27,代码来源:livechan-client.py

示例6: login

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def login(callback=on_chat):
    #image_response = fetch('https://livechan.net/captcha.jpg')
    #image_data = image_response.read()

    #with open('captcha.jpg', 'w') as f:
    #    f.write(image_data)
    #os.system("open captcha.jpg")

    #digits = int(raw_input("enter the captcha: "))
    #post_params = {}
    #post_params["digits"] = digits
    #login_response = post('https://livechan.net/login', post_params)
    #login_html = login_response.read()

    cookie = cookielib.Cookie(version=0, name='password_livechan', value='somepassword', port=None, port_specified=False, domain='livechan.net',
            domain_specified=False, domain_initial_dot=False,
            path='/', path_specified=True, secure=False, expires=None,
            discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
    cookies.set_cookie(cookie)
    livechan_pass = get_password()
    if livechan_pass == "":
        print "wrong password"
        login()

    global socketIO
    socketIO = SocketIO('https://livechan.net',
        cookies={'password_livechan': livechan_pass})
    socketIO.on('chat', callback)
    socketIO.on('request_location', on_request_location)
    
    thread.start_new_thread ( socketIO.wait, () )
开发者ID:emgram769,项目名称:livechan-ircd,代码行数:33,代码来源:livechanapi.py

示例7: __init__

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class LoveSocket:
    def __init__(self):
        self.io = None
        self.hearts = 0
        self.poos = 0

    def start(self):
        threading.Thread(target=self.__start).start()

    def __start(self):
        self.io = SocketIO(LOVE_SOCKET_URL, verify=False)
        self.io.on("love", self.__add_love)
        self.io.on("poo", self.__add_poo)
        self.io.wait()

    def stop(self):
        self.io.disconnect()
        self.io = None

    def reset_hearts(self):
        hearts = self.hearts
        self.hearts = 0
        return hearts

    def reset_poos(self):
        poos = self.poos
        self.poos = 0
        return poos

    def __add_love(self, *args):
        self.hearts += 1

    def __add_poo(self, *args):
        self.poos += 1
开发者ID:aaronfc,项目名称:countdown,代码行数:36,代码来源:LoveSocket.py

示例8: __init__

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class WebSocketIO:
	def __init__(self):
		global host
		global port
		self.socketIO = SocketIO(host, port, LoggingNamespace)
		self.socketIO.on('wiiscale-connect', self.receive_connect)
		self.socketIO.on('wiiscale-disconnect', self.receive_disconnect)

	def wait(self):
		self.socketIO.wait(seconds = 1)

	def send_status(self, status):
		self.socketIO.emit('wiiscale-status', {'status': status})

	def send_weight(self, totalWeight):
		self.socketIO.emit('wiiscale-weight', {'totalWeight': totalWeight})

#	def send_connection_status(self, status):
#		self.socketIO.emit('wiiscale-connection', {'status': status})

	# Accepts True or False as argument
	def receive_connect(self):
		global sleep
		sleep = False

	def receive_disconnect(self):
		global board
		global sleep
		sleep = True
		board.disconnect()
开发者ID:Flerb,项目名称:Wii-Scale,代码行数:32,代码来源:wii-scale.py

示例9: Client

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class Client(object):
  def __init__(self, client_factory):
    self.logger = logging.getLogger('Graduation')
    self.socket = None
    self.client_factory = client_factory
    self.host = client_factory.host
    self.port = client_factory.port

  def connect(self):
    self.socket = SocketIO(self.host, self.port, LoggingNamespace);
    self.socket.on('device_data_response', self.on_response);
    self.sendMessage(0)
    self.socket.wait()

  def on_response(self):
    time.sleep(2);
    tem = random.randint(0, 40);
    self.sendMessage(tem)

  def sendMessage(self, tem):
    data = dict();
    data["id"] = 1
    data["name"] = "name"
    params = dict();
    params["temperature"] = tem
    data["params"] = params
    self.socket.emit('device_data', data)
开发者ID:chenshuchao,项目名称:graduation_design,代码行数:29,代码来源:main.py

示例10: connect

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
def connect():
    """Sends the starting signal to the server."""
    arduino = serial.Serial('/dev/serial/by-id/usb-Gravitech_ARDUINO_NANO_13BP1066-if00-port0', 115200)
    info_start = {'purpose': 'realtime-sender', 'groupID': "cwa2", 'userID': "r0462183"}
    metadata = {'other':"trip ended"} #string "trip ended" stored in metadata under key 'other' to be able to filter on realtime trips easier on the bicyclus website
    print "Setting up for server connection ..."
    while True: #connection tests everywhere they are needed to minimise amount of connection errors
        if try_connection() == True:
            socketIO = SocketIO('dali.cs.kuleuven.be', 8080)
            break
        time.sleep(2)
    while True:
        if try_connection() == True:
            socketIO.on('server_message', on_emit)
            break
        socketIO.wait(2)
    print "Trying to send start signal for trip ..."
    while True:
        if try_connection() == True:
            socketIO.emit('start', json.dumps(info_start), on_emit)
            print "Connection verified, start signal sent."
            socketIO.wait(2)
            break
        socketIO.wait(2)
    info_end = {"_id":startID, "meta": metadata}
    return info_end
开发者ID:bicyclus,项目名称:prototype1,代码行数:28,代码来源:realtime.py

示例11: Broadcaster

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class Broadcaster(object):
    port = 8080
    host = "localhost"

    def __init__(self, port=8080, host="localhost"):
        self.port = port
        self.host = host
        self.socketIO = SocketIO(host, int(port))

        self.socketIO.on("ack", self.logACK)

    def logACK(self, data):
        print("Acknowledgement received for %s" % data['original'])

    def emit(self, event, data):
        self.socketIO.emit(event, data)

    def on(self, event, callback):
        self.socketIO.on(event, callback)

    def wait(self, millis):
        self.socketIO.wait(millis)

    def wait_forever(self):
        self.socketIO.wait()
开发者ID:davidjonas,项目名称:Mediawerf,代码行数:27,代码来源:broadcaster.py

示例12: ListenIO

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
	def ListenIO(self):
		# socketIO = SocketIO('192.168.1.33', 3000)		
		# socketIO = SocketIO('192.168.1.223', 3000)		
		socketIO = SocketIO('localhost', 3000)		
		socketIO.on('serverToPython', self.listener)
		socketIO.emit('clientType', 'Python')
		socketIO.wait(seconds = 6000)
开发者ID:ImmersiveSystems,项目名称:net-robo,代码行数:9,代码来源:ClientClass.py

示例13: WebsocketRemoteControl

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class WebsocketRemoteControl(object):
    def __init__(self, bot):
        self.bot = bot
        self.host, port_str = self.bot.config.websocket_server_url.split(":")
        self.port = int(port_str)
        self.sio = SocketIO(self.host, self.port)
        self.sio.on("bot:process_request:{}".format(self.bot.config.username), self.on_remote_command)
        self.thread = threading.Thread(target=self.process_messages)

    def start(self):
        self.thread.start()
        return self

    def process_messages(self):
        self.sio.wait()

    def on_remote_command(self, command):
        name = command["name"]
        command_handler = getattr(self, name, None)
        if not command_handler or not callable(command_handler):
            self.sio.emit(
                "bot:send_reply", {"response": "", "command": "command_not_found", "account": self.bot.config.username}
            )
            return
        if "args" in command:
            command_handler(*args)
            return
        command_handler()

    def get_player_info(self):
        player_info = self.bot.get_inventory()["responses"]["GET_INVENTORY"]
        self.sio.emit(
            "bot:send_reply", {"result": player_info, "command": "get_player_info", "account": self.bot.config.username}
        )
开发者ID:CadeBrown,项目名称:PokemonGoBot-Manager,代码行数:36,代码来源:websocket_remote_control.py

示例14: SocketServerThread

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
class SocketServerThread(threading.Thread):
    """A socket server to hold the connection."""

    def __init__(self):
        super(SocketServerThread, self).__init__()
        threading.Thread.__init__(self)

    def run(self):
        try:
            print("threading has begun")
            self.io = SocketIO('http://10.224.59.158', 3000, verify=False)
            print("Created new SocketServer")
            self.io.on('connected', self.handleClientMessage)
            self.io.on('reply', self.on_server_response)
            self.io.wait()
            return
        except (e):
            print("There was an error in the server thread.")
        print("threading has completed")
        # self.io.wait(seconds=10)

    def on_connect(self):
        print('[Connected]')

    def on_server_response(self, responseObj):
        print('Server response received', type(responseObj))
        # responseDict = json.loads(responseObj)
        sublime.active_window().active_view().run_command("annotate_log", responseObj)
        

    def handleServerMessage(self, *args):
        print("Server Message", args)

    def handleClientMessage(self, *args):
        print("Client Message", args)
开发者ID:BrandonJF,项目名称:PubSublimePlus,代码行数:37,代码来源:pub2web.py

示例15: check_pushould

# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import on [as 别名]
 def check_pushould(self):
     socketio = SocketIO(self.pushurl,
                         params={"transports": ["polling", "websocket"],
                                 "client_token": str(self.client_token)},
                         verify=False)
     socketio.on('send', self.add_message)
     socketio.emit("subscribe", {"room": "sadpandapush"})
     socketio.wait()
开发者ID:cruor99,项目名称:sadpandareader,代码行数:10,代码来源:main.py


注:本文中的socketIO_client.SocketIO.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。