fix demos for Autobahn 0.4.3
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
import random
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol
|
||||
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
|
||||
|
||||
|
||||
class BroadcastClientProtocol(WebSocketClientProtocol):
|
||||
@@ -36,7 +36,7 @@ class BroadcastClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory()
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = BroadcastClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import sys
|
||||
from twisted.internet import reactor
|
||||
from twisted.python import log
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
|
||||
|
||||
|
||||
class BroadcastServerProtocol(WebSocketServerProtocol):
|
||||
@@ -40,8 +40,8 @@ class BroadcastServerFactory(WebSocketServerFactory):
|
||||
|
||||
protocol = BroadcastServerProtocol
|
||||
|
||||
def __init__(self):
|
||||
WebSocketServerFactory.__init__(self)
|
||||
def __init__(self, url):
|
||||
WebSocketServerFactory.__init__(self, url)
|
||||
self.clients = []
|
||||
self.tickcount = 0
|
||||
self.tick()
|
||||
@@ -71,6 +71,6 @@ class BroadcastServerFactory(WebSocketServerFactory):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = BroadcastServerFactory()
|
||||
reactor.listenTCP(9000, factory)
|
||||
factory = BroadcastServerFactory("ws://localhost:9000")
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -35,7 +35,7 @@ class EchoClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory("ws://localhost:9000", debug = True)
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = EchoClientProtocol
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -20,13 +20,13 @@ import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred, DeferredList
|
||||
from autobahn.websocket import connectWS
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
class MyClientProtocol(WampClientProtocol):
|
||||
"""
|
||||
Demonstrates simple Publish & Subscribe (PubSub) with
|
||||
Autobahn WebSockets and Twisted Deferreds.
|
||||
Demonstrates simple Publish & Subscribe (PubSub) with Autobahn WebSockets.
|
||||
"""
|
||||
|
||||
def show(self, result):
|
||||
@@ -39,15 +39,14 @@ class MyClientProtocol(WampClientProtocol):
|
||||
def done(self, *args):
|
||||
self.sendClose()
|
||||
|
||||
def onFoobar(self, arg):
|
||||
print "FOOBAR", arg
|
||||
arg[3].addCallback(self.onFoobar)
|
||||
def onFoobar(self, topicUri, event):
|
||||
print "FOOBAR", topicUri, event
|
||||
|
||||
def onOpen(self):
|
||||
|
||||
self.prefix("event", "http://resource.example.com/schema/event#")
|
||||
|
||||
self.subscribe("event:foobar").addCallback(self.onFoobar)
|
||||
self.subscribe("event:foobar", self.onFoobar)
|
||||
|
||||
self.publish("event:foobar", {"name": "foo", "value": "bar", "num": 666})
|
||||
self.publish("event:foobar", {"name": "foo", "value": "bar", "num": 666})
|
||||
@@ -60,7 +59,7 @@ class MyClientProtocol(WampClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory = WampClientFactory("ws://localhost:9000")
|
||||
factory.protocol = MyClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys, math
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from autobahn.websocket import listenWS
|
||||
from autobahn.wamp import exportSub, exportPub, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
@@ -90,11 +91,13 @@ class MyServerProtocol(WampServerProtocol):
|
||||
self.topicservice = MyTopicService([1, 3, 7])
|
||||
self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/")
|
||||
|
||||
return WampServerProtocol.onConnect(self, connectionRequest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = WampServerFactory(debug_autobahn = True)
|
||||
factory = WampServerFactory("ws://localhost:9000", debugWamp = True)
|
||||
factory.protocol = MyServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import connectWS
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
@@ -52,7 +53,7 @@ class MyClientProtocol(WampClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory = WampClientFactory("ws://localhost:9000")
|
||||
factory.protocol = MyClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import listenWS
|
||||
from autobahn.wamp import WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
@@ -35,11 +36,13 @@ class MyServerProtocol(WampServerProtocol):
|
||||
## register any URI (string) as topic
|
||||
#self.registerForPubSub("", True)
|
||||
|
||||
return WampServerProtocol.onConnect(self, connectionRequest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = WampServerFactory(debug_autobahn = True)
|
||||
factory = WampServerFactory("ws://localhost:9000", debugWamp = True)
|
||||
factory.protocol = MyServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys, decimal
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import listenWS
|
||||
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
@@ -27,10 +28,10 @@ class CalculatorServerProtocol(WampServerProtocol):
|
||||
def onConnect(self, connectionRequest):
|
||||
self.registerForRpc(self, "http://example.com/simple/calculator#")
|
||||
self.clear()
|
||||
return WampServerProtocol.onConnect(self, connectionRequest)
|
||||
|
||||
|
||||
def clear(self, arg = None):
|
||||
|
||||
self.op = None
|
||||
self.current = decimal.Decimal(0)
|
||||
|
||||
@@ -70,7 +71,7 @@ if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
decimal.getcontext().prec = 20
|
||||
factory = WampServerFactory(debug = False)
|
||||
factory = WampServerFactory("ws://localhost:9000")
|
||||
factory.protocol = CalculatorServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import connectWS
|
||||
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ class KeyValueClientProtocol(WampClientProtocol):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = WampClientFactory(debug = False)
|
||||
factory = WampClientFactory("ws://localhost:9000")
|
||||
factory.protocol = KeyValueClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys, shelve
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import listenWS
|
||||
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||
|
||||
|
||||
@@ -65,13 +66,15 @@ class KeyValueServerProtocol(WampServerProtocol):
|
||||
## this connection
|
||||
self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
|
||||
|
||||
return WampServerProtocol.onConnect(self, connectionRequest)
|
||||
|
||||
|
||||
class KeyValueServerFactory(WampServerFactory):
|
||||
|
||||
protocol = KeyValueServerProtocol
|
||||
|
||||
def __init__(self, debug = False):
|
||||
WampServerFactory.__init__(self, debug)
|
||||
def __init__(self, url):
|
||||
WampServerFactory.__init__(self, url)
|
||||
|
||||
## the key-value store resides on the factory object, since it is to
|
||||
## be shared among all client connections
|
||||
@@ -81,6 +84,6 @@ class KeyValueServerFactory(WampServerFactory):
|
||||
if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
factory = KeyValueServerFactory(debug = False)
|
||||
reactor.listenTCP(9000, factory)
|
||||
factory = KeyValueServerFactory("ws://localhost:9000")
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
from ranstring import randomByteString
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol, connectWS
|
||||
|
||||
FRAME_SIZE = 1 * 2**20
|
||||
|
||||
@@ -48,7 +48,7 @@ class FrameBasedHashClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory()
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = FrameBasedHashClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import hashlib
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
|
||||
|
||||
|
||||
class FrameBasedHashServerProtocol(WebSocketServerProtocol):
|
||||
@@ -43,7 +43,7 @@ class FrameBasedHashServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
factory = WebSocketServerFactory()
|
||||
factory = WebSocketServerFactory("ws://localhost:9000")
|
||||
factory.protocol = FrameBasedHashServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
from ranstring import randomByteString
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol
|
||||
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
|
||||
|
||||
MESSAGE_SIZE = 1 * 2**20
|
||||
|
||||
@@ -47,7 +47,7 @@ class MessageBasedHashClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory()
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = MessageBasedHashClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import hashlib
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
|
||||
|
||||
|
||||
class MessageBasedHashServerProtocol(WebSocketServerProtocol):
|
||||
@@ -36,7 +36,7 @@ class MessageBasedHashServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
factory = WebSocketServerFactory()
|
||||
factory = WebSocketServerFactory("ws://localhost:9000")
|
||||
factory.protocol = MessageBasedHashServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from ranstring import randomByteString
|
||||
from zope.interface import implements
|
||||
from twisted.internet import reactor, interfaces
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol, connectWS
|
||||
|
||||
BATCH_SIZE = 1 * 2**20
|
||||
|
||||
@@ -54,7 +54,7 @@ class StreamingHashClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory()
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = StreamingHashClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from ranstring import randomByteString
|
||||
from zope.interface import implements
|
||||
from twisted.internet import reactor, interfaces
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol
|
||||
from autobahn.websocket import WebSocketProtocol, WebSocketClientFactory, WebSocketClientProtocol, connectWS
|
||||
|
||||
FRAME_SIZE = 0x7FFFFFFFFFFFFFFF # 2^63 - This is the maximum imposed by the WS protocol
|
||||
|
||||
@@ -80,7 +80,7 @@ class StreamingProducerHashClientProtocol(WebSocketClientProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
factory = WebSocketClientFactory()
|
||||
factory = WebSocketClientFactory("ws://localhost:9000")
|
||||
factory.protocol = StreamingProducerHashClientProtocol
|
||||
reactor.connectTCP("localhost", 9000, factory)
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import hashlib
|
||||
from twisted.internet import reactor
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
|
||||
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
|
||||
from streaming_client import BATCH_SIZE
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class StreamingHashServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
factory = WebSocketServerFactory()
|
||||
factory = WebSocketServerFactory("ws://localhost:9000")
|
||||
factory.protocol = StreamingHashServerProtocol
|
||||
reactor.listenTCP(9000, factory)
|
||||
listenWS(factory)
|
||||
reactor.run()
|
||||
|
||||
Reference in New Issue
Block a user