本文整理汇总了Python中autobahn.websocket.WebSocketServerFactory.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketServerFactory.protocol方法的具体用法?Python WebSocketServerFactory.protocol怎么用?Python WebSocketServerFactory.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.websocket.WebSocketServerFactory
的用法示例。
在下文中一共展示了WebSocketServerFactory.protocol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startService
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def startService(self):
factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % self.port)
factory.protocol = EchoServerProtocol
# FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
factory.startFactory()
resource = WebSocketResource(factory)
# we server static files under "/" ..
webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
root = File(webdir)
# and our WebSocket server under "/ws" (note that Twisted uses
# bytes for URIs)
root.putChild(b"ws", resource)
# both under one Twisted Web Site
site = Site(root)
self.site = site
self.factory = factory
self.listener = reactor.listenTCP(self.port, site)
示例2: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main(curDir):
class WhiteboardServerProtocol(WebSocketServerProtocol):
def onConnect(self, connectionRequest):
whiteboard.addClient(self)
return None
def onMessage(self, msg, binary):
whiteboard.processMessage(self, msg)
os.chdir(curDir)
#log.startLogging(sys.stdout)
debugWS = False
debugWhiteboard = False
whiteboard = WhiteboardServer(debugWhiteboard)
factory = WebSocketServerFactory("ws://localhost:9000",
debug = debugWS,
debugCodePaths = debugWS)
factory.protocol = WhiteboardServerProtocol
#factory.setProtocolOptions(allowHixie76 = True)
listenWS(factory)
webdir = File(".")
web = Site(webdir)
reactor.listenTCP(8080, web)
#threading.Thread(None, reactor.run, None).start()
print "Starting websocket server"
reactor.run()
whiteboard.shutdown()
示例3: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main():
""" Main method for the websocket server """
LOG.info('main: Start')
udp_steward = UDPConnectionSteward()
udp_steward.start()
# Uncomment these two to get log from twisted
#import sys
#log.startLogging(sys.stdout)
# Create context factor with key and certificate
context_factory = ssl.DefaultOpenSSLContextFactory(
'/home/kenni/Dokumenter/websockets/autobahn/keys/server.key',
'/home/kenni/Dokumenter/websockets/autobahn/keys/server.crt'
)
# Form the webserver factory
factory = WebSocketServerFactory("wss://localhost:9001", debug=True)
# Set the handler
factory.protocol = CinfWebSocketHandler
# Listen for incoming WebSocket connections: wss://localhost:9001
listenWS(factory, context_factory)
try:
reactor.run() # pylint: disable=E1101
time.sleep(1)
LOG.info('main: Keyboard interrupt, websocket reactor stopped')
udp_steward.stop()
time.sleep(1)
LOG.info('main: UPD Steward stopped')
except Exception as exception_:
LOG.exception(exception_)
raise exception_
LOG.info('main: Ended')
raw_input('All stopped. Press enter to exit')
示例4: startService
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def startService(self):
factory = WebSocketServerFactory("ws://localhost:%d" % self.port, debug=self.debug)
factory.protocol = EchoServerProtocol
factory.setProtocolOptions(allowHixie76=True) # needed if Hixie76 is to be supported
# FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
factory.startFactory()
resource = WebSocketResource(factory)
# we server static files under "/" ..
webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
root = File(webdir)
# and our WebSocket server under "/ws"
root.putChild("ws", resource)
# both under one Twisted Web Site
site = Site(root)
site.protocol = HTTPChannelHixie76Aware # needed if Hixie76 is to be supported
self.site = site
self.factory = factory
self.listener = reactor.listenTCP(self.port, site)
示例5: serve_wss
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def serve_wss(self):
"""Start a web socket server over SSL, used by the web UI to get notifications about updates."""
import os
from .events import SystemEvent
# Start a web socket server if the web UI is enabled
if not self._config['web-ui-enabled']:
return
if not self._config['wss-enabled']:
return
if not os.path.isfile(self._config['ssl-cert']):
self._startup_event.log_critical("Unable to activate SSL: File does not exist: %s" % self._config['ssl-cert'])
return
try:
import os
from autobahn.websocket import WebSocketServerProtocol, WebSocketServerFactory
from twisted.internet import reactor, ssl
from twisted.internet.error import BindError
# Create a WebSocketClientHandler instance
WebSocketClientHandler = WebSocketClientHandlerFactory(self._config, self._ws_clients, self._event_store, self._server_status)
uri = u"ws://%s:%s" % (self._config['wss-host'], self._config['wss-port'])
factory = WebSocketServerFactory(uri)
factory.protocol = WebSocketClientHandler
# factory.setProtocolOptions(maxConnections=2)
# note to self: if using putChild, the child must be bytes...
if self._config['ssl-key'] and self._config['ssl-cert']:
contextFactory = ssl.DefaultOpenSSLContextFactory(privateKeyFileName=self._config['ssl-key'], certificateFileName=self._config['ssl-cert'])
else:
contextFactory = ssl.DefaultOpenSSLContextFactory(privateKeyFileName=self._config['ssl-cert'], certificateFileName=self._config['ssl-cert'])
self._ws_server_port = reactor.listenSSL(self._config['wss-port'], factory, contextFactory)
# self._ws_server_port = reactor.listenTCP(self._config['wss-port'], factory)
self._server_status['wss-uri'] = "wss://%s:%s" % (self._config['wss-host'], self._config['wss-port'])
self._startup_event.log_info("Listening for connections on %s" % self._server_status['wss-uri'])
self._startup_event.ws_address = self._config['wss-host']
self._startup_event.ws_port = self._config['wss-port']
self._startup_event.set_ws_started(True)
# Serve forever (until reactor.stop())
reactor.run(installSignalHandlers=False)
except BindError as e:
self._startup_event.log_critical("Unable to start web socket server: %s" % e)
except ImportError:
self._startup_event.log_error("Unable to start web socket server due to missing dependency.")
event = SystemEvent()
self._event_store.register_action(event)
event.log_info('WSS server did quit')
示例6: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main():
log.startLogging(sys.stdout)
factory = WebSocketServerFactory("ws://localhost:9000", debug = False)
factory.protocol = EchoServerProtocol
listenWS(factory)
reactor.run()
示例7: __init__
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def __init__(self):
global kwizz
kwizz=self
self.players=[]
self.games=[]
factory = WebSocketServerFactory("ws://localhost:9000", debug = False)
factory.protocol = KwizzLiveProtocol
reactor.listenTCP(9000, factory)
reactor.run()
示例8: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", metavar="PORT=3000", type=int, default=3000)
myapp.setup_argparser(parser)
args = parser.parse_args()
myapp.setup_app(args)
factory = WebSocketServerFactory("ws://localhost:%d" % args.port)
factory.protocol = WebSocketWrapperProtocol
root = Root()
root.putChild("ws", WebSocketResource(factory))
reactor.listenTCP(args.port, Site(root))
reactor.run()
示例9: getAutoBahn
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def getAutoBahn(core, port=80):
#from twisted.python import log as tlog
#tlog.startLogging(sys.stdout)
wsuri = "ws://localhost"
if not port in ['80','443']:
wsuri+=":"+str(port)
#factory = WebSocketServerFactory(wsuri, debug=True, debugCodePaths=True)
factory = WebSocketServerFactory(wsuri)
factory.core = core
factory.protocol = AutobahnProtocolWrapper
factory.setProtocolOptions(allowHixie76 = True)
resource = WebSocketResource(factory)
log.debug("AutoBahn started")
return resource
示例10: start_server
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def start_server(port, appmanager, protocol, apprate, netrate):
port = 9999
manager = Manager(appmanager, apprate, netrate) # TODO remove manager = ?
DefaultConnection.__bases__ += (Protocol, protocol, Sender) # WTF inheritance
echofactory = Factory()
echofactory.protocol = DefaultConnection
reactor.listenTCP(port, echofactory)
# WEBSOOOOOCKKEEEET
WSConnection.__bases__ += (WebSocketServerProtocol, protocol, Sender)
factory = WebSocketServerFactory("ws://localhost:" + str(port + 1))
factory.protocol = WSConnection
listenWS(factory)
print "Server initialized"
reactor.run()
示例11: _setUpListener
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def _setUpListener(self, serviceName, port, protocol, handler=None):
url = "ws://localhost:%d"%(port)
factory = WebSocketServerFactory(url, debug=True, debugCodePaths=True)
factory.protocol = protocol
factory.setProtocolOptions(allowHixie76=True)
#HACK: add an array for observing messages
factory.observers = [] #called for every message; for the ui to listen
if handler !=None:
factory.observers.append(handler)
factory.connections = [] #all connections that are active; for the protocol to send data
self.frontEndListeners[serviceName] = factory
listenWS(self.frontEndListeners[serviceName])
示例12: start_web
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def start_web(localEPG=None, playout_service=None, playout=None, port=8888, schedule=None):
root = File('web')
if schedule:
root.putChild("schedules", SchedulesPage(schedule))
root.putChild("player_snapshots", File('cache/snapshots'))
root.putChild("stills", StillsListPage("stills"))
wrapper = simple_guard_resource(root)
site = Site(wrapper)
reactor.listenTCP(port, site)
factory = WebSocketServerFactory()
factory.protocol = lambda: PlayoutWebsocketProtocol (playout_service, playout, schedule)
reactor.listenTCP(8889, factory)
"""
示例13: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main():
try:
#initializing serial flashing etc utilities socket
ServerFactory = BroadcastServerFactory
factory = ServerFactory("ws://localhost:9000")
# factory = WebSocketServerFactory("ws://localhost:9000", debug = False)
factory.protocol = EchoServerProtocol
listenWS(factory)
factory2 = WebSocketServerFactory("ws://localhost:9001")
factory2.protocol = WebSerialProtocol
listenWS(factory2)
reactor.run()
except error.CannotListenError, e:
print "Port is already used. Exiting..."
os._exit(0)
示例14: main
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
def main():
""" Main method for the websocket server """
LOG.info('main: Start')
global LIVESOCKET # pylint: disable=global-statement
names = ['wss_hosts_defined', 'wss_hosts', 'wss_clients']
LIVESOCKET = LiveSocket('websocketserver', names, sane_interval=1.0)
LIVESOCKET.start()
udp_steward = UDPConnectionSteward()
udp_steward.start()
# Uncomment these two to get log from twisted
#import sys
#log.startLogging(sys.stdout)
# Create context factor with key and certificate
context_factory = ssl.DefaultOpenSSLContextFactory(
'/home/kenni/certs/fysik.dtu.dk.key',
'/home/kenni/certs/fysik.dtu.dk.crt'
)
# Form the webserver factory
factory = WebSocketServerFactory("wss://localhost:9001", debug=True)
# Set the handler
factory.protocol = CinfWebSocketHandler
# Listen for incoming WebSocket connections: wss://localhost:9001
listenWS(factory, context_factory)
try:
reactor.run() # pylint: disable=E1101
time.sleep(1)
LOG.info('main: Keyboard interrupt, websocket reactor stopped')
udp_steward.stop()
time.sleep(1)
LOG.info('main: UPD Steward stopped')
LIVESOCKET.stop()
time.sleep(1)
LOG.info('main: Own livesocket stoppped')
except Exception as exception_:
LOG.exception(exception_)
raise exception_
LOG.info('main: Ended')
raw_input('All stopped. Press enter to exit')
示例15: onMessageFrameEnd
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import protocol [as 别名]
rest = length - (self.received - self.next)
self.sha256.update(data[:rest])
## send digest
digest = self.sha256.hexdigest()
self.sendMessage(digest)
print "Sent digest for batch %d : %s" % (self.count, digest)
## advance to next batch
self.next += BATCH_SIZE
self.count += 1
## .. and update the digest for the rest
self.sha256.update(data[rest:])
else:
## otherwise we just update the digest for received data
self.sha256.update(data)
def onMessageFrameEnd(self):
pass
def onMessageEnd(self):
pass
if __name__ == '__main__':
factory = WebSocketServerFactory("ws://localhost:9000")
factory.protocol = StreamingHashServerProtocol
listenWS(factory)
reactor.run()