-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.py
More file actions
59 lines (46 loc) · 1.53 KB
/
server.py
File metadata and controls
59 lines (46 loc) · 1.53 KB
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
from twisted.internet import reactor, ssl
import twisted.internet.protocol as twistedsockets
from twisted.python import log
import sys
from autobahn.websocket import listenWS
from rpi_ws.server_protocol import RPIServerProtocol, RPISocketServerFactory, SiteComm, FlashSocketPolicyServerProtocol
from twisted.web import server
# SSL applies to both HTTP and WS
WS_USE_SSL = False
HTTP_USE_SSL = False
WS_PORT = 9000
SERVER = "localhost"
DEBUG = False
HTTP_PORT = 8090
PROVIDEFLASHSOCKETPOLICYFILE = True
def main():
if WS_USE_SSL or HTTP_USE_SSL:
contextFactory = ssl.DefaultOpenSSLContextFactory('certs/server.key',
'certs/server.crt')
if WS_USE_SSL:
uri_type = "wss"
else:
uri_type = "ws"
server_url = "%s://%s:%d" % (uri_type, SERVER, WS_PORT)
if DEBUG:
log.startLogging(sys.stdout)
factory = RPISocketServerFactory(server_url, debug=DEBUG, debugCodePaths=DEBUG)
factory.protocol = RPIServerProtocol
sitecomm = SiteComm(factory)
factory.sitecomm = sitecomm
site = server.Site(sitecomm)
if WS_USE_SSL:
listenWS(factory, contextFactory)
else:
listenWS(factory)
if HTTP_USE_SSL:
reactor.listenSSL(HTTP_PORT, site, contextFactory)
else:
reactor.listenTCP(HTTP_PORT, site)
if PROVIDEFLASHSOCKETPOLICYFILE:
socketfactory = twistedsockets.Factory()
socketfactory.protocol = FlashSocketPolicyServerProtocol
reactor.listenTCP(843, socketfactory)
reactor.run()
if __name__ == '__main__':
main()