-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
48 lines (35 loc) · 1.33 KB
/
server.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
#!/usr/bin/python
import sys
import resources
import storage
from twisted.internet.protocol import DatagramProtocol
from twisted.web import server
from twisted.application import service, internet
from twisted.python import log
from django.conf import settings
storage.load()
settings.configure(TEMPLATE_DIRS=('templates',))
class UDPServer(DatagramProtocol):
def datagramReceived(self, datagram, address):
data = datagram.strip().decode('cp1251')
storage.put(data)
class Service(service.Service):
def startService(self):
log.startLogging(sys.stdout)
service.Service.startService(self)
log.msg('ErrorDigest server started')
_topService = service.MultiService()
_service = Service()
_service.setServiceParent(_topService)
root = resources.Root('media')
root.putChild('pattern', resources.Pattern('pattern.html'))
root.putChild('data', resources.Data('data.html'))
root.putChild('digest', resources.Digest('digest.html'))
root.putChild('metrics', resources.Metrics('metrics.html'))
_factory = server.Site(root)
_tcpService = internet.TCPServer(8080, _factory)
_udpService = internet.UDPServer(8001, UDPServer())
_udpService.setServiceParent(_topService)
_tcpService.setServiceParent(_topService)
application = service.Application("ErrorDigest")
_topService.setServiceParent(application)