-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscheduler.py
47 lines (33 loc) · 1.29 KB
/
scheduler.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
import web
import settings
import sys
from models import ModelHandler
from twisted.web.wsgi import WSGIResource
from twisted.web.server import Site
from twisted.internet import reactor, protocol
from twisted.python import log
class AMCPHandler(object):
def __init__(self):
pass
class AMCPProtocol(protocol.Protocol):
def connectionMade(self):
log.msg("connect with server %s build" % self.transport.getPeer())
# self.transport.write("CLS\r\n")
def dataReceived(self, data):
log.msg("%s" % data)
class AMCPFactory(protocol.ClientFactory):
def buildProtocol(self, addr):
return AMCPProtocol()
def clientConnectionFailed(self, connector, reason):
print "Connection between server failed, reason :%s" % reason
def clientConnectionLost(self, connector, reason):
print "Connection between server lost, reason :%s" % reason
# register a web for twisted's WSGI application
resource = WSGIResource(reactor, reactor.getThreadPool(), web.app)
site = Site(resource)
if __name__ == "__main__":
log.startLogging(sys.stdout)
model = ModelHandler()
reactor.listenTCP(settings.__WEBCLIENT_PORT__, site)
reactor.connectTCP(settings.__CASPARCG_SERVER_IP__, settings.__CASPARCG_SERVER_PORT__, AMCPFactory())
reactor.run()