| 1 | from twisted.internet import protocol, reactor |
|---|
| 2 | from twisted.application import service, internet |
|---|
| 3 | |
|---|
| 4 | class NotifyProtocol(protocol.Protocol): |
|---|
| 5 | def __init__(self): |
|---|
| 6 | self.host_key = None |
|---|
| 7 | def dataReceived(self, data): |
|---|
| 8 | self.factory.count += 1 |
|---|
| 9 | print "%s clients have connected." % self.factory.count |
|---|
| 10 | self.transport.write("HTTP/1.x 200 OK\r\n\r\n") |
|---|
| 11 | |
|---|
| 12 | class NotifyFactory(protocol.ServerFactory): |
|---|
| 13 | protocol = NotifyProtocol |
|---|
| 14 | def __init__(self): |
|---|
| 15 | self.count = 0 |
|---|
| 16 | |
|---|
| 17 | application = service.Application('NotifyServer') |
|---|
| 18 | internet.TCPServer(2000, NotifyFactory(), interface="0.0.0.0", backlog=50000).setServiceParent(service.IServiceCollection(application)) |
|---|