-
Notifications
You must be signed in to change notification settings - Fork 5
/
relay.py
74 lines (58 loc) · 2.21 KB
/
relay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
#sdfwe
#relay.py
#Author: Anirudh Sanjeev (anirudh -at- anirudhsanjeev -dot- org)
from stompservice import StompClientFactory
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from random import random
from orbited import json
from SimpleXMLRPCServer import *
from threading import Thread
import stompservice
INTERVAL = 1000
class DataProducer(StompClientFactory):
def recv_connected(self, msg):
print 'Connected; producing data'
# the next two lines are probably the biggest workaround
# for the weirdest bug I've seen in my entire life
# it repeatedly calls a function that absolutely does nothing
# however, if I remove them, there's a ten second delay
# between when the DataProducer transmits a message to
# when the browser actually receives the data. Me and my
# friend were mindfucked thinking about how something like
# this could possibly happen. But right now we are more worried
# about the rest of the code
self.timer = LoopingCall(self.test_data)
self.timer.start(INTERVAL/1000.0)
def send_data(self, channel, data):
print "Transmitting: ", data
# modify our data elements
self.send(channel, json.encode(data))
def test_data(self):
# WHAT THE F***?
pass
orbited_proxy = DataProducer()
class RPCServer(Thread):
def __init__(self, orbited):
self.orbited = orbited
Thread.__init__(self)
def run(self):
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
#create a server
server = SimpleXMLRPCServer(("localhost",8045),requestHandler = RequestHandler)
server.register_introspection_functions()
def transmit_orbited(channel, message):
"""
@param channel: The stomp channel to send to
@param message: The message that needs to be transmitted
"""
self.orbited.send_data(channel, message)
return ""
server.register_function(transmit_orbited, 'transmit')
server.serve_forever()
rpcthread = RPCServer(orbited_proxy)
rpcthread.start()
reactor.connectTCP('localhost', 61613, orbited_proxy)
reactor.run()