Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, handler_class, host='127.0.0.1', port=0, **kwargs):
self._server = make_server(
host, port, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=handler_class)
)
self._server.initialize_websockets_manager()
super(WebsocketServer, self).__init__(
name=self.__class__,
target=self._server.serve_forever
)
"""
from wsgiref.simple_server import make_server
from ws4py.websocket import EchoWebSocket
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
from ws4py.server.wsgiutils import WebSocketWSGIApplication
app = WebSocketWSGIApplication(handler_cls=EchoWebSocket)
if async:
def middleware(app):
def later(environ, start_response):
for part in app(environ, start_response):
yield part
return later
app = middleware(app)
server = make_server(host, port, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=app)
server.initialize_websockets_manager()
server.serve_forever()
def run(self):
def handler_cls_builder(*args, **kwargs):
return self.__webSocketServerClass(*args, **kwargs)
self.__server = simple_server.make_server(
self.__host,
self.__port,
server_class=wsgirefserver.WSGIServer,
handler_class=wsgirefserver.WebSocketWSGIRequestHandler,
app=wsgiutils.WebSocketWSGIApplication(handler_cls=handler_cls_builder)
)
self.__server.initialize_websockets_manager()
self.__server.serve_forever()
def start_server(host, port):
global wserver
if wserver:
return False
wserver = make_server(host, port,
server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=WebSocketApp)
)
wserver.initialize_websockets_manager()
wserver_thread = threading.Thread(target=wserver.serve_forever)
wserver_thread.daemon = True
wserver_thread.start()
bpy.app.handlers.frame_change_post.append(frame_change_post)
bpy.app.handlers.load_post.append(load_post)
bpy.app.handlers.save_post.append(save_post)
return True
from wsgiref.simple_server import make_server
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
from ws4py.server.wsgiutils import WebSocketWSGIApplication
from wshubsapi.connection_handlers.ws4py_handler import ConnectionHandler
from wshubsapi.hubs_inspector import HubsInspector
if __name__ == '__main__':
HubsInspector.include_hubs_in("*_hub.py") # use glob path patterns
HubsInspector.inspect_implemented_hubs() # setup api
HubsInspector.construct_python_file("../Clients/_static/hubs_api.py") # only if you will use a python client
HubsInspector.construct_js_file("../Clients/_static/hubsApi.js") # only if you will use a js client
server = make_server('127.0.0.1', 8888, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=ConnectionHandler))
server.initialize_websockets_manager()
server.serve_forever()
if message.data != "STOP":
self.q_popen = Queue()
self.scriptThread = Process(target = runCode, args = (message, self, self.q_popen))
self.scriptThread.start()
else:
print "Kill Process"
self.q_popen.get().kill()
# print self.scriptThread.terminate()
# print self.__popen.kill()
def closed(self, code, reason=None):
clients.remove(self)
if hasattr(self, 'q_popen') and not self.q_popen.empty():
self.q_popen.get().kill()
server = make_server('', 7320, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=PythonDaemon))
def quit_everything(signal, frame):
global server
print 'Exiting...'
server.server_close()
signal.signal(signal.SIGINT, quit_everything)
server.initialize_websockets_manager()
print "Listening..."
server.serve_forever()
"""
if hasattr(self, 'manager'):
self.manager.close_all()
self.manager.stop()
self.manager.join()
delattr(self, 'manager')
_WSGIServer.server_close(self)
if __name__ == '__main__':
from ws4py import configure_logger
configure_logger()
from wsgiref.simple_server import make_server
from ws4py.websocket import EchoWebSocket
server = make_server('', 9000, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=EchoWebSocket))
server.initialize_websockets_manager()
try:
server.serve_forever()
except KeyboardInterrupt:
server.server_close()
def run(self):
from . import server
self.server = make_server(
'', 9222, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=server.DebuggerWebSocket))
sys.stderr.write(
'Navigate to chrome://devtools/devtools.html?ws=0.0.0.0:9222\n')
self.server.initialize_websockets_manager()
self.server.serve_forever()
def __init__(self, port=5570, cb_recept = None, log = None ):
global __ctrlServer__
self.buffer = []
self.clients = set()
self.fail_clients = set()
self.running = False
self.port = port
self.cb_recept = cb_recept
self.log = log
self.server = make_server('', port, server_class=WSGIServer,
handler_class=WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=WebSocketsHandler))
self.server.initialize_websockets_manager()
__ctrlServer__ = self
servUI = threading.Thread(None, self.run, "th_WSserv_msg_to_ui", (), {} )
servUI.start()
time.sleep(0.1)
self.log.info('WebSocket server started on port : %d' %self.port)
print "**************** WebSocket server is started ********************"
logger.info('Initializing camera')
with picamera.PiCamera() as camera:
config = get_config()
w = config.getint('camera', 'width', fallback=640)
h = config.getint('camera', 'height', fallback=480)
camera.resolution = (w, h)
camera.framerate = config.getint('camera', 'framerate', fallback=24)
camera.rotation = config.getint('camera', 'rotation', fallback=0)
camera.hflip = config.getboolean('camera', 'hflip', fallback=False)
camera.vflip = config.getboolean('camera', 'vflip', fallback=False)
camera.led = config.getboolean('camera', 'led', fallback=False)
sleep(1) # camera warm-up tim
logger.info('Initializing websockets server on port %d' % WS_PORT)
websocket_server = make_server(
'', WS_PORT,
server_class=WSGIServer,
handler_class=HTTP11WebSocketWSGIRequestHandler,
app=WebSocketWSGIApplication(handler_cls=StreamingWebSocket))
websocket_server.initialize_websockets_manager()
websocket_thread = Thread(target=websocket_server.serve_forever)
#logger.info('Initializing HTTP server on port %d' % HTTP_PORT)
#http_server = StreamingHttpServer()
#http_thread = Thread(target=http_server.serve_forever)
logger.debug('Initializing broadcast thread')
output = BroadcastOutput(camera)
broadcast_thread = BroadcastThread(output.converter, websocket_server)
logger.info('Starting recording')
camera.start_recording(output, 'yuv')
try:
logger.debug('Starting websockets thread')
websocket_thread.start()
#logger.info('Starting HTTP server thread')