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


Python SimpleWebSocketServer.serveforever方法代码示例

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


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

示例1: WSServerThread

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class WSServerThread( threading.Thread ):
	"""
	La clase cliente socket que se levanta como un hilo de proceso 
	independiente.
	"""
	def __init__ ( self, sktServer):
		"""
		Inicializacion de la clase
		"""
		self.wshandlerclass = ''
		self.sktServer = sktServer
		self.wSktServer = SimpleWebSocketServer('', 9000, SimpleEcho)
		threading.Thread.__init__ ( self )


	def setWSHandlerClass(self, instance):
		self.wshandlerclass = instance


	def run ( self ):
		"""
		Una vez inicializada la clase esta es ejecutada en este metodo
		"""
		self.wSktServer.setInvoker(self)
		self.sktServer.attach(self)
		self.wSktServer.serveforever()

	def sendMessage(self, data):
		if self.wshandlerclass != '':
			self.wshandlerclass.send_bytes(data)
开发者ID:ppvasqueze,项目名称:bolas_sag,代码行数:32,代码来源:proxysws.py

示例2: WebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class WebSocketServer(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.server = SimpleWebSocketServer("", WEB_SOCKET_PORT_NUMBER, WebSocketHandler)


    def run(self):
        log.info("Starting WebSocketServer on port %d" % WEB_SOCKET_PORT_NUMBER)
        self.server.serveforever()
开发者ID:hex007,项目名称:pifm_server,代码行数:11,代码来源:main.py

示例3: runServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def runServer():
	server = SimpleWebSocketServer("", 8532, VaticServer)

	def close_sig_handler(signal, frame):
		server.close()
		sys.exit()

	signal.signal(signal.SIGINT, close_sig_handler)

	server.serveforever()
开发者ID:vovakkk,项目名称:vatic,代码行数:12,代码来源:wsserver.py

示例4: NetworkServerSocket

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class NetworkServerSocket(Thread):
    def __init__(self, lettre):
        Thread.__init__(self)
        self.server = SimpleWebSocketServer("", portWebSocket, ClientWebSocket)
        print "WEBSOCKET listenning ..."

    def run(self):
        self.server.serveforever()

    def broadcastAll(self, jsonMessage):
        for c in clients:
            c.sendMessage(json.dumps(jsonMessage, ensure_ascii=False))
开发者ID:Blackout76,项目名称:Cab-Rel,代码行数:14,代码来源:NetworkWebSocket.py

示例5: serve

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def serve():

    '''
    class InputServer(WebSocket):
        tilt = 0
        def __init__(self, *args, **kwargs):
            super(InputServer, self).__init__(*args, **kwargs)
            self.runloop = None

        def handleConnected(self):
            print(self.address, 'connected')
            self.runloop = input.KinectLoop(self)
            self.runloop.start()

        def handleClose(self):
            self.runloop.kill()
            print(self.address, 'closed')

        def handleMessage(self):
            self.tilt = int(float(self.data))
    '''
    class InputServer(WebSocket):

        def __init__(self, *args, **kwargs):
            super(InputServer, self).__init__(*args, **kwargs)
            self.kinect = None
            self.oid = None

        def handleConnected(self):
            print self.address, 'connected'
            self.kinect = KinectFactory.create_kinect()
            self.oid = uuid.uuid1()
            self.kinect.add_observer(self.oid, self.send_depth)

        def handleClose(self):
            self.kinect.remove_observer(self.oid)
            print self.address, 'closed'

        def handleMessage(self):
            degs = int(float(self.data))
            self.kinect.set_tilt(degs)

        def send_depth(self, depth):
            self.sendMessage(depth)

    def close_sig_handler(signum, frame):
        server.close()
        KinectFactory.kill()
        sys.exit()

    signal.signal(signal.SIGINT, close_sig_handler)
    server = SimpleWebSocketServer('0.0.0.0', 1337, InputServer)
    server.serveforever()
开发者ID:regar007,项目名称:Kimotion,代码行数:55,代码来源:server.py

示例6: main

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def main():
    print("Starting WebSocket ...")
    server = SimpleWebSocketServer('localhost', 8000, DataServer)
    print("WebSocket Ready!")

    def close_sig_handler(signal, frame):
        print("\nClosing WebSocket ...")
        server.close()
        print("Bye!")
        sys.exit()

    signal.signal(signal.SIGINT, close_sig_handler)
    server.serveforever()
开发者ID:lumbric,项目名称:angezeige,代码行数:15,代码来源:web_socket.py

示例7: Server

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class Server(Thread):
    def run(self):
        """Starts the thread for the Web Socket Server"""
        host = ""
        port = 8008
        self.server = SimpleWebSocketServer(host, port, Logger)

        print("serving")
        self.server.serveforever()

    def close_sig_handler(self, signal, frame):
        """Function called upon Ctrl+C that kills the program"""
        print("closing")
        self.server.close()
开发者ID:LoganGirard,项目名称:EyeTribe,代码行数:16,代码来源:EyeReader.py

示例8: FSWebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class FSWebSocketServer(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.port = 8010
        self._logger = logging.getLogger(__name__)

    def run(self):
        #try:
            self._logger.info("Websocket Server started on port %s" % self.port)
            self.wsd = SimpleWebSocketServer('', self.port, FSWebSocket)
            self.wsd.serveforever()
        #except:
        #    self._logger.error("WebSocket Crash!")
开发者ID:bootinge,项目名称:FabScanPi-Server,代码行数:16,代码来源:__init__.py

示例9: FSWebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class FSWebSocketServer(FSWebSocketServerInterface):

    def __init__(self):
        super(FSWebSocketServerInterface, self).__init__(group=None)
        self.port = 8010
        self._logger = logging.getLogger(__name__)

    def run(self):
            self._logger.info("Websocket Server started on port %s" % self.port)
            try:
                self.wsd = SimpleWebSocketServer('', self.port, FSWebSocket)
                self.wsd.serveforever()
            except:
                self._logger.error("Websocket not started")
开发者ID:jenshackel,项目名称:FabScanPi-Server,代码行数:16,代码来源:__init__.py

示例10: socketServerThread

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class socketServerThread(threading.Thread):
	def __init__(self, host, port, socketQueue):
		threading.Thread.__init__(self)
		self.cls = socketServer
		self.socketQueue = socketQueue
		self.server = SimpleWebSocketServer(host, port, self.socketQueue, self.cls)
	
	def run(self):
		print "starting Server"
		self.server.serveforever()
		
	def exit(self):
		print "stoping Server"
		self.server.close()
开发者ID:mattfullerton,项目名称:Zoidberg,代码行数:16,代码来源:socketServer.py

示例11: startServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def startServer():
  server = SimpleWebSocketServer('', 12345, SimpleEcho)
  server.serveforever()
开发者ID:Leo7676,项目名称:raspi-car,代码行数:5,代码来源:controller.py

示例12: print

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
    httpserver = SocketServer.TCPServer(
        ('', HTTP_PORT), SimpleHTTPRequestHandler)
    print('car http server port: %d' % HTTP_PORT)
    httpd = threading.Thread(target=httpserver.serve_forever)
    httpd.start()
    websocket = SimpleWebSocketServer('', WEBSOCKET_PORT, CommandWebsocket)

    def close_sig_handler(signal, frame):
        #car.quit()
        httpserver.shutdown()
        httpd.join()
        websocket.close()

        print('quit')
        sys.exit()

    signal.signal(signal.SIGINT, close_sig_handler)
    while True:
        websocket.serveforever()
        if grove_sound_sensor.read_sound_sensor_values() >= SoundLimen:
            if Flag == 0:
                Flag = 1
                print 'Turn On'
                GPIO.output(RELAY, GPIO.HIGH)
            elif Flag == 1:
                Flag = 0
                print 'Turn Off'
                GPIO.output(RELAY, GPIO.LOW)
                
            
开发者ID:Lee-Kevin,项目名称:Smart_Light_BBG,代码行数:30,代码来源:light_server.py

示例13: startServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def startServer():
    server = SimpleWebSocketServer('', 8080, SockClient)
    server.serveforever()
开发者ID:sbhavani,项目名称:rtl_heatmap,代码行数:5,代码来源:rtl_heatmap_server.py

示例14: WebSocket_GUI

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
class Server_GUI:
	class WebSocket_GUI(WebSocket):
		def handleMessage(self):
			mode = self.data[:1]
			message = self.data[1:]			
			if (mode == '0'):			# PLAY
				obj_Music.play_pause()
			elif (mode == '1'):			# STOP
				obj_Music.stop()
			elif (mode == '2'):			# PREVIOUS
				obj_Playlist.prev()
			elif (mode == '3'):			# NEXT
				obj_Playlist.button_next()
			elif (mode == '4'):			# VOLUME
				obj_Music.set_volume(float(message))
			elif (mode == '5'):			# PLAY INDEX
				obj_Playlist.play_index(int(message))
			elif (mode == '6'):			# SEEK
				obj_Music.seek(float(message))
			elif (mode == '7'):			# MUTE
				obj_Music.mute_toggle()	
			elif (mode == '8'):			# PLAYLIST CYCLE MODE
				obj_Playlist.change_mode()

		def handleConnected(self):
			print self.address, 'connected'
			Server_GUI.update_all(self);

		def handleClose(self): print self.address, 'closed'

	def __init__(self):
		self.server = SimpleWebSocketServer('0.0.0.0', 8000, self.WebSocket_GUI)

		signal.signal(signal.SIGINT, self.close_sig_handler)
		logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

		thread.start_new_thread(self.thread_main,())
		thread.start_new_thread(self.thread_change,())

		print "Server open!"

	@staticmethod
	def string_playing(): return '"playing":' + str(obj_Music.get_playing()).lower() + ','

	@staticmethod
	def string_index(): return '"index":' + str(obj_Playlist.index).lower() + ','

	@staticmethod
	def string_files():
		string = '"files":['
		for title in obj_Playlist.array_titles:
			string += '"' + title + '",'
		return string[:-1] + '],'

	@staticmethod
	def string_length():
		string = '"lengths":['
		for length in obj_Playlist.array_length:
			string += str(length) + ','
		return string[:-1] + '],'
	
	@staticmethod
	def string_position(): return '"time":' + str(obj_Music.get_time()) + ','

	@staticmethod
	def string_volume(): return '"volume":' + str(obj_Music.get_volume()) + ','

	@staticmethod
	def string_mute(): return '"mute":' + str(obj_Music.mute).lower() + ','

	@staticmethod
	def string_mode(): return '"mode":' + str(obj_Playlist.mode) + ','
	
	@staticmethod
	def string_cycles():
		string = '"cycles":["'
		for x in obj_Playlist.array_cycles:
			string += x + '","'
		return (string[:-2] + '],').replace("\r", "\n").replace("\n\n", "\n").replace("\n", "\\n")
		
	@staticmethod
	def string_cycles_index():
		string = '"cycles_index":['
		for x in obj_Playlist.array_cycles_index:
			string += str(x) + ','
		return string[:-1] + '],'

	def send_to_all(self, string):
		for conn in self.server.connections.itervalues():
			conn.sendMessage(string)

	def thread_main(self):
		self.server.serveforever()

	@staticmethod
	def update_all(client):
		client.sendMessage("0{" + Server_GUI.string_cycles_index() + Server_GUI.string_cycles() + Server_GUI.string_mode() + Server_GUI.string_mute() + Server_GUI.string_volume() + Server_GUI.string_position() + Server_GUI.string_length() + Server_GUI.string_index() + Server_GUI.string_files() + Server_GUI.string_playing()[:-1] + "}")

	def thread_change(self):
		global running
#.........这里部分代码省略.........
开发者ID:Joseph14078,项目名称:raspmusicbox-server,代码行数:103,代码来源:server.py

示例15: startWebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleWebSocketServer import serveforever [as 别名]
def startWebSocketServer():
  socketServer = SimpleWebSocketServer('', websocket_port, TestWebSocket)
  socketServer.serveforever()
开发者ID:albertosarullo,项目名称:Wall-E-Lego-Raspberry-Camera-First-Person-View-AR-VR,代码行数:5,代码来源:websocket_server.py


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