fix demos for Autobahn 0.4.3

This commit is contained in:
Tobias Oberstein
2011-11-23 11:44:41 +01:00
parent 6015d4b488
commit a37adbc329
17 changed files with 64 additions and 53 deletions

View File

@@ -18,7 +18,7 @@
import random import random
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
class BroadcastClientProtocol(WebSocketClientProtocol): class BroadcastClientProtocol(WebSocketClientProtocol):
@@ -36,7 +36,7 @@ class BroadcastClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory() factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = BroadcastClientProtocol factory.protocol = BroadcastClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -19,7 +19,7 @@
import sys import sys
from twisted.internet import reactor from twisted.internet import reactor
from twisted.python import log from twisted.python import log
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
class BroadcastServerProtocol(WebSocketServerProtocol): class BroadcastServerProtocol(WebSocketServerProtocol):
@@ -40,8 +40,8 @@ class BroadcastServerFactory(WebSocketServerFactory):
protocol = BroadcastServerProtocol protocol = BroadcastServerProtocol
def __init__(self): def __init__(self, url):
WebSocketServerFactory.__init__(self) WebSocketServerFactory.__init__(self, url)
self.clients = [] self.clients = []
self.tickcount = 0 self.tickcount = 0
self.tick() self.tick()
@@ -71,6 +71,6 @@ class BroadcastServerFactory(WebSocketServerFactory):
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = BroadcastServerFactory() factory = BroadcastServerFactory("ws://localhost:9000")
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -35,7 +35,7 @@ class EchoClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory("ws://localhost:9000", debug = True) factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = EchoClientProtocol factory.protocol = EchoClientProtocol
connectWS(factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -20,13 +20,13 @@ import sys
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
from autobahn.websocket import connectWS
from autobahn.wamp import WampClientFactory, WampClientProtocol from autobahn.wamp import WampClientFactory, WampClientProtocol
class MyClientProtocol(WampClientProtocol): class MyClientProtocol(WampClientProtocol):
""" """
Demonstrates simple Publish & Subscribe (PubSub) with Demonstrates simple Publish & Subscribe (PubSub) with Autobahn WebSockets.
Autobahn WebSockets and Twisted Deferreds.
""" """
def show(self, result): def show(self, result):
@@ -39,15 +39,14 @@ class MyClientProtocol(WampClientProtocol):
def done(self, *args): def done(self, *args):
self.sendClose() self.sendClose()
def onFoobar(self, arg): def onFoobar(self, topicUri, event):
print "FOOBAR", arg print "FOOBAR", topicUri, event
arg[3].addCallback(self.onFoobar)
def onOpen(self): def onOpen(self):
self.prefix("event", "http://resource.example.com/schema/event#") 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})
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__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = WampClientFactory(debug = False) factory = WampClientFactory("ws://localhost:9000")
factory.protocol = MyClientProtocol factory.protocol = MyClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys, math import sys, math
from twisted.python import log from twisted.python import log
from twisted.internet import reactor, defer from twisted.internet import reactor, defer
from autobahn.websocket import listenWS
from autobahn.wamp import exportSub, exportPub, WampServerFactory, WampServerProtocol from autobahn.wamp import exportSub, exportPub, WampServerFactory, WampServerProtocol
@@ -90,11 +91,13 @@ class MyServerProtocol(WampServerProtocol):
self.topicservice = MyTopicService([1, 3, 7]) self.topicservice = MyTopicService([1, 3, 7])
self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/") self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/")
return WampServerProtocol.onConnect(self, connectionRequest)
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = WampServerFactory(debug_autobahn = True) factory = WampServerFactory("ws://localhost:9000", debugWamp = True)
factory.protocol = MyServerProtocol factory.protocol = MyServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys import sys
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import connectWS
from autobahn.wamp import WampClientFactory, WampClientProtocol from autobahn.wamp import WampClientFactory, WampClientProtocol
@@ -52,7 +53,7 @@ class MyClientProtocol(WampClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = WampClientFactory(debug = False) factory = WampClientFactory("ws://localhost:9000")
factory.protocol = MyClientProtocol factory.protocol = MyClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys import sys
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import listenWS
from autobahn.wamp import WampServerFactory, WampServerProtocol from autobahn.wamp import WampServerFactory, WampServerProtocol
@@ -35,11 +36,13 @@ class MyServerProtocol(WampServerProtocol):
## register any URI (string) as topic ## register any URI (string) as topic
#self.registerForPubSub("", True) #self.registerForPubSub("", True)
return WampServerProtocol.onConnect(self, connectionRequest)
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = WampServerFactory(debug_autobahn = True) factory = WampServerFactory("ws://localhost:9000", debugWamp = True)
factory.protocol = MyServerProtocol factory.protocol = MyServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys, decimal import sys, decimal
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import listenWS
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
@@ -27,10 +28,10 @@ class CalculatorServerProtocol(WampServerProtocol):
def onConnect(self, connectionRequest): def onConnect(self, connectionRequest):
self.registerForRpc(self, "http://example.com/simple/calculator#") self.registerForRpc(self, "http://example.com/simple/calculator#")
self.clear() self.clear()
return WampServerProtocol.onConnect(self, connectionRequest)
def clear(self, arg = None): def clear(self, arg = None):
self.op = None self.op = None
self.current = decimal.Decimal(0) self.current = decimal.Decimal(0)
@@ -70,7 +71,7 @@ if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
decimal.getcontext().prec = 20 decimal.getcontext().prec = 20
factory = WampServerFactory(debug = False) factory = WampServerFactory("ws://localhost:9000")
factory.protocol = CalculatorServerProtocol factory.protocol = CalculatorServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys import sys
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import connectWS
from autobahn.wamp import WampClientFactory, WampClientProtocol from autobahn.wamp import WampClientFactory, WampClientProtocol
@@ -42,7 +43,7 @@ class KeyValueClientProtocol(WampClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = WampClientFactory(debug = False) factory = WampClientFactory("ws://localhost:9000")
factory.protocol = KeyValueClientProtocol factory.protocol = KeyValueClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -19,6 +19,7 @@
import sys, shelve import sys, shelve
from twisted.python import log from twisted.python import log
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import listenWS
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
@@ -65,13 +66,15 @@ class KeyValueServerProtocol(WampServerProtocol):
## this connection ## this connection
self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#") self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
return WampServerProtocol.onConnect(self, connectionRequest)
class KeyValueServerFactory(WampServerFactory): class KeyValueServerFactory(WampServerFactory):
protocol = KeyValueServerProtocol protocol = KeyValueServerProtocol
def __init__(self, debug = False): def __init__(self, url):
WampServerFactory.__init__(self, debug) WampServerFactory.__init__(self, url)
## the key-value store resides on the factory object, since it is to ## the key-value store resides on the factory object, since it is to
## be shared among all client connections ## be shared among all client connections
@@ -81,6 +84,6 @@ class KeyValueServerFactory(WampServerFactory):
if __name__ == '__main__': if __name__ == '__main__':
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
factory = KeyValueServerFactory(debug = False) factory = KeyValueServerFactory("ws://localhost:9000")
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -18,7 +18,7 @@
from ranstring import randomByteString from ranstring import randomByteString
from twisted.internet import reactor 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 FRAME_SIZE = 1 * 2**20
@@ -48,7 +48,7 @@ class FrameBasedHashClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory() factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = FrameBasedHashClientProtocol factory.protocol = FrameBasedHashClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -18,7 +18,7 @@
import hashlib import hashlib
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
class FrameBasedHashServerProtocol(WebSocketServerProtocol): class FrameBasedHashServerProtocol(WebSocketServerProtocol):
@@ -43,7 +43,7 @@ class FrameBasedHashServerProtocol(WebSocketServerProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketServerFactory() factory = WebSocketServerFactory("ws://localhost:9000")
factory.protocol = FrameBasedHashServerProtocol factory.protocol = FrameBasedHashServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -18,7 +18,7 @@
from ranstring import randomByteString from ranstring import randomByteString
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol from autobahn.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
MESSAGE_SIZE = 1 * 2**20 MESSAGE_SIZE = 1 * 2**20
@@ -47,7 +47,7 @@ class MessageBasedHashClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory() factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = MessageBasedHashClientProtocol factory.protocol = MessageBasedHashClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -18,7 +18,7 @@
import hashlib import hashlib
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
class MessageBasedHashServerProtocol(WebSocketServerProtocol): class MessageBasedHashServerProtocol(WebSocketServerProtocol):
@@ -36,7 +36,7 @@ class MessageBasedHashServerProtocol(WebSocketServerProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketServerFactory() factory = WebSocketServerFactory("ws://localhost:9000")
factory.protocol = MessageBasedHashServerProtocol factory.protocol = MessageBasedHashServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()

View File

@@ -19,7 +19,7 @@
from ranstring import randomByteString from ranstring import randomByteString
from zope.interface import implements from zope.interface import implements
from twisted.internet import reactor, interfaces 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 BATCH_SIZE = 1 * 2**20
@@ -54,7 +54,7 @@ class StreamingHashClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory() factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = StreamingHashClientProtocol factory.protocol = StreamingHashClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -19,7 +19,7 @@
from ranstring import randomByteString from ranstring import randomByteString
from zope.interface import implements from zope.interface import implements
from twisted.internet import reactor, interfaces 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 FRAME_SIZE = 0x7FFFFFFFFFFFFFFF # 2^63 - This is the maximum imposed by the WS protocol
@@ -80,7 +80,7 @@ class StreamingProducerHashClientProtocol(WebSocketClientProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketClientFactory() factory = WebSocketClientFactory("ws://localhost:9000")
factory.protocol = StreamingProducerHashClientProtocol factory.protocol = StreamingProducerHashClientProtocol
reactor.connectTCP("localhost", 9000, factory) connectWS(factory)
reactor.run() reactor.run()

View File

@@ -18,7 +18,7 @@
import hashlib import hashlib
from twisted.internet import reactor from twisted.internet import reactor
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS
from streaming_client import BATCH_SIZE from streaming_client import BATCH_SIZE
@@ -75,7 +75,7 @@ class StreamingHashServerProtocol(WebSocketServerProtocol):
if __name__ == '__main__': if __name__ == '__main__':
factory = WebSocketServerFactory() factory = WebSocketServerFactory("ws://localhost:9000")
factory.protocol = StreamingHashServerProtocol factory.protocol = StreamingHashServerProtocol
reactor.listenTCP(9000, factory) listenWS(factory)
reactor.run() reactor.run()