Instantly share code, notes, and snippets.

Embed
What would you like to do?
from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketClientFactory
from os import environ
from twisted.internet import reactor, protocol
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.wamp import ApplicationRunner
from twisted.internet.defer import inlineCallbacks
from autobahn import wamp
class EchoClient(protocol.Protocol):
"""Once connected, send a message, then print the result."""
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
print("Connection established to Asseco Payment Terminal")
self.factory.echoers.append(self)
def dataReceived(self, data):
"As soon as any data is received, write it back."
print("Server said:", data)
def connectionLost(self, reason):
print("connection lost")
def send_data(self, wjat):
print 'Send datat'
finalmessage = "\x02\x02000000000001000\x1c1\x1c\x1c+0\x1c978\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c\x1c00\x1c\x1c\x1c\x03."
print repr(finalmessage)
self.transport.write(finalmessage)
class EchoFactory(protocol.ClientFactory):
protocol = EchoClient
def clientConnectionFailed(self, connector, reason):
print("Connection failed - goodbye!")
reactor.stop()
def clientConnectionLost(self, connector, reason):
print("Connection lost - goodbye!")
reactor.stop()
class LocalInterface(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
yield self.register(self)
print("Connection established to local websocket network")
@wamp.register(u'com.example.posterminal.test')
def handle_test(self,data):
print 'Test event recieved'
print ccc
f.protocol.send_data()
return 32
class local_websockets:
def __init__(self):
self.runner = ApplicationRunner(environ.get("AUTOBAHN_DEMO_ROUTER", u"ws://127.0.0.1:8080/ws"),
u"realm1",)
def start(self):
# Same as above
self.runner.run(LocalInterface, start_reactor=False)
if __name__ == '__main__':
import sys
from twisted.python import log
from twisted.internet import reactor
log.startLogging(sys.stdout)
local = local_websockets()
local.start()
f = EchoFactory()
reactor.connectTCP(u'192.168.88.250', 3000, f)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment