renamed autobahn _module_ to wamp; dito for classes
@@ -20,10 +20,10 @@ import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred, DeferredList
|
||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
class ClientProtocol(AutobahnClientProtocol):
|
||||
class MyClientProtocol(WampClientProtocol):
|
||||
"""
|
||||
Demonstrates simple Publish & Subscribe (PubSub) with
|
||||
Autobahn WebSockets and Twisted Deferreds.
|
||||
@@ -53,14 +53,14 @@ class ClientProtocol(AutobahnClientProtocol):
|
||||
self.publish("event:foobar", {"name": "foo", "value": "bar", "num": 666})
|
||||
self.publish("event:foobar-extended", {"name": "foo", "value": "bar", "num": 42})
|
||||
self.publish("event:foobar-limited", {"name": "foo", "value": "bar", "num": 23})
|
||||
|
||||
|
||||
#self.done()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnClientFactory(debug = False)
|
||||
factory.protocol = ClientProtocol
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory.protocol = MyClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
import sys, math
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from autobahn.autobahn import exportSub, exportPub, AutobahnServerFactory, AutobahnServerProtocol
|
||||
from autobahn.wamp import exportSub, exportPub, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
class TopicService:
|
||||
class MyTopicService:
|
||||
|
||||
def __init__(self, allowedTopicIds):
|
||||
self.allowedTopicIds = allowedTopicIds
|
||||
@@ -73,7 +73,7 @@ class TopicService:
|
||||
return None
|
||||
|
||||
|
||||
class SimpleServerProtocol(AutobahnServerProtocol):
|
||||
class MyServerProtocol(WampServerProtocol):
|
||||
|
||||
def onConnect(self, connectionRequest):
|
||||
|
||||
@@ -87,14 +87,14 @@ class SimpleServerProtocol(AutobahnServerProtocol):
|
||||
#self.registerForPubSub("", True)
|
||||
|
||||
## register a topic handler to control topic subscriptions/publications
|
||||
self.topicservice = TopicService([1, 3, 7])
|
||||
self.topicservice = MyTopicService([1, 3, 7])
|
||||
self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnServerFactory(debug_autobahn = True)
|
||||
factory.protocol = SimpleServerProtocol
|
||||
factory = WampServerFactory(debug_autobahn = True)
|
||||
factory.protocol = MyServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
import sys, decimal
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
||||
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
class CalculatorServerProtocol(AutobahnServerProtocol):
|
||||
class CalculatorServerProtocol(WampServerProtocol):
|
||||
|
||||
def onConnect(self, connectionRequest):
|
||||
self.registerForRpc(self, "http://example.com/simple/calculator#")
|
||||
@@ -70,7 +70,7 @@ if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
decimal.getcontext().prec = 20
|
||||
factory = AutobahnServerFactory(debug = False)
|
||||
factory = WampServerFactory(debug = False)
|
||||
factory.protocol = CalculatorServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
class KeyValueClientProtocol(AutobahnClientProtocol):
|
||||
class KeyValueClientProtocol(WampClientProtocol):
|
||||
|
||||
def done(self, *args):
|
||||
self.sendClose()
|
||||
@@ -42,7 +42,7 @@ class KeyValueClientProtocol(AutobahnClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnClientFactory(debug = False)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory.protocol = KeyValueClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import sys, shelve
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
||||
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
class KeyValue:
|
||||
@@ -48,7 +48,7 @@ class KeyValue:
|
||||
return self.store.keys()
|
||||
|
||||
|
||||
class KeyValueServerProtocol(AutobahnServerProtocol):
|
||||
class KeyValueServerProtocol(WampServerProtocol):
|
||||
"""
|
||||
Demonstrates creating a server with Autobahn WebSockets that provides
|
||||
a persistent key-value store which can we access via RPCs.
|
||||
@@ -60,12 +60,12 @@ class KeyValueServerProtocol(AutobahnServerProtocol):
|
||||
self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
|
||||
|
||||
|
||||
class KeyValueServerFactory(AutobahnServerFactory):
|
||||
class KeyValueServerFactory(WampServerFactory):
|
||||
|
||||
protocol = KeyValueServerProtocol
|
||||
|
||||
def __init__(self, debug = False):
|
||||
AutobahnServerFactory.__init__(self, debug)
|
||||
WampServerFactory.__init__(self, debug)
|
||||
|
||||
## the key-value store resides on the factory object, since it is to
|
||||
## be shared among all client connections
|
||||
|
||||
@@ -20,10 +20,10 @@ import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred, DeferredList
|
||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
class SimpleClientProtocol(AutobahnClientProtocol):
|
||||
class SimpleClientProtocol(WampClientProtocol):
|
||||
"""
|
||||
Demonstrates simple Remote Procedure Calls (RPC) with
|
||||
Autobahn WebSockets and Twisted Deferreds.
|
||||
@@ -66,7 +66,7 @@ class SimpleClientProtocol(AutobahnClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnClientFactory(debug = False)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory.protocol = SimpleClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -20,10 +20,10 @@ import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred, returnValue, inlineCallbacks
|
||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
class SimpleClientProtocol(AutobahnClientProtocol):
|
||||
class SimpleClientProtocol(WampClientProtocol):
|
||||
"""
|
||||
Demonstrates simple Remote Procedure Calls (RPC) with
|
||||
Autobahn WebSockets and Twisted Inline Callbacks.
|
||||
@@ -71,7 +71,7 @@ class SimpleClientProtocol(AutobahnClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnClientFactory(debug = False)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory.protocol = SimpleClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import sys, math
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
||||
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
class Calc:
|
||||
@@ -66,7 +66,7 @@ class Calc:
|
||||
return d
|
||||
|
||||
|
||||
class SimpleServerProtocol(AutobahnServerProtocol):
|
||||
class SimpleServerProtocol(WampServerProtocol):
|
||||
"""
|
||||
Demonstrates creating a simple server with Autobahn WebSockets that
|
||||
responds to RPC calls.
|
||||
@@ -86,7 +86,7 @@ class SimpleServerProtocol(AutobahnServerProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = AutobahnServerFactory(debug = False)
|
||||
factory = WampServerFactory(debug = False)
|
||||
factory.protocol = SimpleServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
reactor.run()
|
||||
|
||||
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 213 KiB After Width: | Height: | Size: 213 KiB |
@@ -41,7 +41,7 @@ Contents
|
||||
websocketprotocol
|
||||
websocketclient
|
||||
websocketserver
|
||||
autobahnprotocol
|
||||
wamp
|
||||
|
||||
|
||||
Protocol Classes
|
||||
@@ -50,8 +50,8 @@ Protocol Classes
|
||||
* :class:`autobahn.websocket.WebSocketProtocol`
|
||||
* :class:`autobahn.websocket.WebSocketClientProtocol`
|
||||
* :class:`autobahn.websocket.WebSocketServerProtocol`
|
||||
* :class:`autobahn.autobahn.AutobahnClientProtocol`
|
||||
* :class:`autobahn.autobahn.AutobahnServerProtocol`
|
||||
* :class:`autobahn.wamp.WampClientProtocol`
|
||||
* :class:`autobahn.wamp.WampServerProtocol`
|
||||
|
||||
.. image:: protocolclasses.png
|
||||
|
||||
@@ -60,8 +60,8 @@ Factory Classes
|
||||
|
||||
* :class:`autobahn.websocket.WebSocketClientFactory`
|
||||
* :class:`autobahn.websocket.WebSocketServerFactory`
|
||||
* :class:`autobahn.autobahn.AutobahnClientFactory`
|
||||
* :class:`autobahn.autobahn.AutobahnServerFactory`
|
||||
* :class:`autobahn.wamp.WampClientFactory`
|
||||
* :class:`autobahn.wamp.WampServerFactory`
|
||||
|
||||
.. image:: factoryclasses.png
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 197 KiB |
@@ -1,45 +1,45 @@
|
||||
Autobahn RPC/PubSub
|
||||
===================
|
||||
Autobahn WebSockets RPC/PubSub
|
||||
==============================
|
||||
|
||||
RPC/PubSub Servers
|
||||
------------------
|
||||
|
||||
The classes :class:`autobahn.autobahn.AutobahnServerProtocol` and
|
||||
:class:`autobahn.autobahn.AutobahnServerFactory` are the base classes
|
||||
you derive from to implement Autobahn RPC/PubSub servers.
|
||||
The classes :class:`autobahn.wamp.WampServerProtocol` and
|
||||
:class:`autobahn.wamp.WampServerFactory` are the base classes
|
||||
you derive from to implement Autobahn WebSockets RPC/PubSub servers.
|
||||
|
||||
|
||||
.. autoclass:: autobahn.autobahn.AutobahnServerProtocol
|
||||
.. autoclass:: autobahn.wamp.WampServerProtocol
|
||||
:members: registerForRpc,
|
||||
registerMethodForRpc,
|
||||
registerProcedureForRpc
|
||||
|
||||
.. autoclass:: autobahn.autobahn.AutobahnServerFactory
|
||||
.. autoclass:: autobahn.wamp.WampServerFactory
|
||||
|
||||
|
||||
RPC/PubSub Clients
|
||||
------------------
|
||||
|
||||
The classes :class:`autobahn.autobahn.AutobahnClientProtocol` and
|
||||
:class:`autobahn.autobahn.AutobahnClientFactory` are the base classes
|
||||
you derive from to implement Autobahn RPC/PubSub clients.
|
||||
The classes :class:`autobahn.wamp.WampClientProtocol` and
|
||||
:class:`autobahn.wamp.WampClientFactory` are the base classes
|
||||
you derive from to implement Autobahn WebSockets RPC/PubSub clients.
|
||||
|
||||
|
||||
.. autoclass:: autobahn.autobahn.AutobahnClientProtocol
|
||||
.. autoclass:: autobahn.wamp.WampClientProtocol
|
||||
:members: prefix,
|
||||
call,
|
||||
subscribe,
|
||||
unsubscribe,
|
||||
publish
|
||||
|
||||
.. autoclass:: autobahn.autobahn.AutobahnClientFactory
|
||||
.. autoclass:: autobahn.wamp.WampClientFactory
|
||||
|
||||
|
||||
|
||||
RPC/PubSub Protocol
|
||||
-------------------
|
||||
|
||||
.. autoclass:: autobahn.autobahn.AutobahnProtocol
|
||||
.. autoclass:: autobahn.wamp.WampProtocol
|
||||
:members: MESSAGE_TYPEID_NULL,
|
||||
MESSAGE_TYPEID_PREFIX,
|
||||
MESSAGE_TYPEID_CALL,
|
||||
@@ -17,7 +17,7 @@
|
||||
###############################################################################
|
||||
|
||||
import websocket
|
||||
import autobahn
|
||||
import wamp
|
||||
import fuzzing
|
||||
import case
|
||||
import prefixmap
|
||||
|
||||
@@ -64,9 +64,9 @@ def exportPub(arg, prefixMatch = False):
|
||||
return inner
|
||||
|
||||
|
||||
class AutobahnProtocol:
|
||||
class WampProtocol:
|
||||
"""
|
||||
Base protocol class for Autobahn RPC/PubSub.
|
||||
Base protocol class for Wamp RPC/PubSub.
|
||||
"""
|
||||
|
||||
MESSAGE_TYPEID_NULL = 0
|
||||
@@ -132,9 +132,9 @@ class AutobahnProtocol:
|
||||
|
||||
def _protocolError(self, reason):
|
||||
if self.debug_autobahn:
|
||||
log.msg("Closing Autobahn session on protocol violation : %s" % reason)
|
||||
log.msg("Closing Wamp session on protocol violation : %s" % reason)
|
||||
#self.failConnection()
|
||||
self.sendClose(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, "Autobahn RPC/PubSub protocol violation ('%s')" % reason)
|
||||
self.sendClose(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, "Wamp RPC/PubSub protocol violation ('%s')" % reason)
|
||||
|
||||
|
||||
def shrink(self, uri):
|
||||
@@ -173,14 +173,14 @@ class AutobahnProtocol:
|
||||
return self.prefixes.resolveOrPass(curieOrUri)
|
||||
|
||||
|
||||
class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
class WampServerProtocol(WebSocketServerProtocol, WampProtocol):
|
||||
"""
|
||||
Server factory for Autobahn RPC/PubSub.
|
||||
Server factory for Wamp RPC/PubSub.
|
||||
"""
|
||||
|
||||
def connectionMade(self):
|
||||
WebSocketServerProtocol.connectionMade(self)
|
||||
AutobahnProtocol.connectionMade(self)
|
||||
WampProtocol.connectionMade(self)
|
||||
|
||||
## RPCs registered in this session (a URI map of (object, procedure)
|
||||
## pairs for object methods or (None, procedure) for free standing procedures)
|
||||
@@ -198,7 +198,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
def connectionLost(self, reason):
|
||||
self.factory._unsubscribeClient(self)
|
||||
|
||||
AutobahnProtocol.connectionLost(self, reason)
|
||||
WampProtocol.connectionLost(self, reason)
|
||||
WebSocketServerProtocol.connectionLost(self, reason)
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
def _sendCallResult(self, result, callid):
|
||||
## Internal method for marshaling/sending an RPC success result.
|
||||
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, callid, result]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, callid, result]
|
||||
try:
|
||||
o = json.dumps(msg)
|
||||
except:
|
||||
@@ -397,12 +397,12 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
eargs = error.value.args
|
||||
|
||||
if len(eargs) == 0:
|
||||
erroruri = AutobahnProtocol.ERROR_URI_GENERIC
|
||||
errordesc = AutobahnProtocol.ERROR_DESC_GENERIC
|
||||
erroruri = WampProtocol.ERROR_URI_GENERIC
|
||||
errordesc = WampProtocol.ERROR_DESC_GENERIC
|
||||
elif len(eargs) == 1:
|
||||
if type(eargs[0]) not in [str, unicode]:
|
||||
raise Exception("invalid type for exception description")
|
||||
erroruri = AutobahnProtocol.ERROR_URI_GENERIC
|
||||
erroruri = WampProtocol.ERROR_URI_GENERIC
|
||||
errordesc = eargs[0]
|
||||
else:
|
||||
if type(eargs[0]) not in [str, unicode]:
|
||||
@@ -412,15 +412,15 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
erroruri = eargs[0]
|
||||
errordesc = eargs[1]
|
||||
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR, callid, self.prefixes.shrink(erroruri), errordesc]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_CALL_ERROR, callid, self.prefixes.shrink(erroruri), errordesc]
|
||||
self.sendMessage(json.dumps(msg))
|
||||
|
||||
|
||||
def onMessage(self, msg, binary):
|
||||
## Internal method handling Autobahn messages received from client.
|
||||
## Internal method handling Wamp messages received from client.
|
||||
|
||||
if self.debug_autobahn:
|
||||
log.msg("AutobahnServerProtocol message received : %s" % str(msg))
|
||||
log.msg("WampServerProtocol message received : %s" % str(msg))
|
||||
|
||||
if not binary:
|
||||
try:
|
||||
@@ -429,7 +429,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
|
||||
## Call Message
|
||||
##
|
||||
if obj[0] == AutobahnProtocol.MESSAGE_TYPEID_CALL:
|
||||
if obj[0] == WampProtocol.MESSAGE_TYPEID_CALL:
|
||||
callid = obj[1]
|
||||
procuri = self.prefixes.resolveOrPass(obj[2])
|
||||
arg = obj[3:]
|
||||
@@ -439,7 +439,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
|
||||
## Subscribe Message
|
||||
##
|
||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_SUBSCRIBE:
|
||||
elif obj[0] == WampProtocol.MESSAGE_TYPEID_SUBSCRIBE:
|
||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||
h = self._getSubHandler(topicuri)
|
||||
if h:
|
||||
@@ -476,13 +476,13 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
|
||||
## Unsubscribe Message
|
||||
##
|
||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_UNSUBSCRIBE:
|
||||
elif obj[0] == WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE:
|
||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||
self.factory._unsubscribeClient(self, topicuri)
|
||||
|
||||
## Publish Message
|
||||
##
|
||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_PUBLISH:
|
||||
elif obj[0] == WampProtocol.MESSAGE_TYPEID_PUBLISH:
|
||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||
h = self._getPubHandler(topicuri)
|
||||
if h:
|
||||
@@ -521,7 +521,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
|
||||
## Define prefix to be used in CURIEs
|
||||
##
|
||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_PREFIX:
|
||||
elif obj[0] == WampProtocol.MESSAGE_TYPEID_PREFIX:
|
||||
prefix = obj[1]
|
||||
uri = obj[2]
|
||||
self.prefixes.set(prefix, uri)
|
||||
@@ -536,12 +536,12 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
||||
log.msg("binary message")
|
||||
|
||||
|
||||
class AutobahnServerFactory(WebSocketServerFactory):
|
||||
class WampServerFactory(WebSocketServerFactory):
|
||||
"""
|
||||
Server factory for Autobahn RPC/PubSub.
|
||||
Server factory for Wamp RPC/PubSub.
|
||||
"""
|
||||
|
||||
protocol = AutobahnServerProtocol
|
||||
protocol = WampServerProtocol
|
||||
|
||||
def __init__(self, debug = False, debug_autobahn = False):
|
||||
WebSocketServerFactory.__init__(self, debug = debug)
|
||||
@@ -583,7 +583,7 @@ class AutobahnServerFactory(WebSocketServerFactory):
|
||||
|
||||
if self.subscriptions.has_key(topicuri):
|
||||
if len(self.subscriptions[topicuri]) > 0:
|
||||
o = [AutobahnProtocol.MESSAGE_TYPEID_EVENT, topicuri, event]
|
||||
o = [WampProtocol.MESSAGE_TYPEID_EVENT, topicuri, event]
|
||||
try:
|
||||
msg = json.dumps(o)
|
||||
if self.debug_autobahn:
|
||||
@@ -603,35 +603,35 @@ class AutobahnServerFactory(WebSocketServerFactory):
|
||||
|
||||
def startFactory(self):
|
||||
if self.debug_autobahn:
|
||||
log.msg("AutobahnServerFactory starting")
|
||||
log.msg("WampServerFactory starting")
|
||||
self.subscriptions = {}
|
||||
|
||||
|
||||
def stopFactory(self):
|
||||
if self.debug_autobahn:
|
||||
log.msg("AutobahnServerFactory stopped")
|
||||
log.msg("WampServerFactory stopped")
|
||||
|
||||
|
||||
class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
class WampClientProtocol(WebSocketClientProtocol, WampProtocol):
|
||||
"""
|
||||
Client protocol for Autobahn RPC/PubSub.
|
||||
Client protocol for Wamp RPC/PubSub.
|
||||
"""
|
||||
|
||||
def connectionMade(self):
|
||||
WebSocketClientProtocol.connectionMade(self)
|
||||
AutobahnProtocol.connectionMade(self)
|
||||
WampProtocol.connectionMade(self)
|
||||
|
||||
self.calls = {}
|
||||
self.subscriptions = {}
|
||||
|
||||
|
||||
def connectionLost(self, reason):
|
||||
AutobahnProtocol.connectionLost(self, reason)
|
||||
WampProtocol.connectionLost(self, reason)
|
||||
WebSocketClientProtocol.connectionLost(self, reason)
|
||||
|
||||
|
||||
def onMessage(self, msg, binary):
|
||||
## Internal method to handle received Autobahn messages.
|
||||
## Internal method to handle received Wamp messages.
|
||||
|
||||
if binary:
|
||||
self._protocolError("binary message received")
|
||||
@@ -655,10 +655,10 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
|
||||
msgtype = obj[0]
|
||||
|
||||
if msgtype not in [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR, AutobahnProtocol.MESSAGE_TYPEID_EVENT]:
|
||||
if msgtype not in [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, WampProtocol.MESSAGE_TYPEID_CALL_ERROR, WampProtocol.MESSAGE_TYPEID_EVENT]:
|
||||
self._protocolError("invalid message type '%d'" % msgtype)
|
||||
|
||||
if msgtype in [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR]:
|
||||
if msgtype in [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, WampProtocol.MESSAGE_TYPEID_CALL_ERROR]:
|
||||
if len(obj) < 2:
|
||||
self._protocolError("call result/error message without callid")
|
||||
return
|
||||
@@ -668,13 +668,13 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
callid = str(obj[1])
|
||||
d = self.calls.pop(callid, None)
|
||||
if d:
|
||||
if msgtype == AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT:
|
||||
if msgtype == WampProtocol.MESSAGE_TYPEID_CALL_RESULT:
|
||||
if len(obj) != 3:
|
||||
self._protocolError("call result message invalid length")
|
||||
return
|
||||
result = obj[2]
|
||||
d.callback(result)
|
||||
elif msgtype == AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR:
|
||||
elif msgtype == WampProtocol.MESSAGE_TYPEID_CALL_ERROR:
|
||||
if len(obj) != 4:
|
||||
self._protocolError("call error message invalid length")
|
||||
return
|
||||
@@ -694,7 +694,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
else:
|
||||
if self.debug_autobahn:
|
||||
log.msg("callid not found for received call result/error message")
|
||||
elif msgtype == AutobahnProtocol.MESSAGE_TYPEID_EVENT:
|
||||
elif msgtype == WampProtocol.MESSAGE_TYPEID_EVENT:
|
||||
if len(obj) != 3:
|
||||
self._protocolError("event message invalid length")
|
||||
return
|
||||
@@ -733,7 +733,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
break
|
||||
d = Deferred()
|
||||
self.calls[callid] = d
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL, callid, procuri]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_CALL, callid, procuri]
|
||||
msg.extend(args[1:])
|
||||
|
||||
try:
|
||||
@@ -767,7 +767,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
|
||||
self.prefixes.set(prefix, uri)
|
||||
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_PREFIX, prefix, uri]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_PREFIX, prefix, uri]
|
||||
|
||||
self.sendMessage(json.dumps(msg))
|
||||
|
||||
@@ -787,7 +787,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
if type(topicuri) not in [unicode, str]:
|
||||
raise Exception("invalid type for URI")
|
||||
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_PUBLISH, topicuri, event]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_PUBLISH, topicuri, event]
|
||||
|
||||
try:
|
||||
o = json.dumps(msg)
|
||||
@@ -807,7 +807,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
"""
|
||||
d = Deferred()
|
||||
self.subscriptions[self.prefixes.resolveOrPass(topicuri)] = d
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_SUBSCRIBE, topicuri]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_SUBSCRIBE, topicuri]
|
||||
o = json.dumps(msg)
|
||||
self.sendMessage(o)
|
||||
return d
|
||||
@@ -821,18 +821,18 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
||||
:type topicuri: str
|
||||
"""
|
||||
del self.subscriptions[topicuri]
|
||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicuri]
|
||||
msg = [WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicuri]
|
||||
o = json.dumps(msg)
|
||||
self.sendMessage(o)
|
||||
return d
|
||||
|
||||
|
||||
class AutobahnClientFactory(WebSocketClientFactory):
|
||||
class WampClientFactory(WebSocketClientFactory):
|
||||
"""
|
||||
Client factory for Autobahn RPC/PubSub.
|
||||
Client factory for Wamp RPC/PubSub.
|
||||
"""
|
||||
|
||||
protocol = AutobahnClientProtocol
|
||||
protocol = WampClientProtocol
|
||||
|
||||
def __init__(self, debug = False, debug_autobahn = False):
|
||||
WebSocketClientFactory.__init__(self, debug = debug)
|
||||