Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

process_twisted.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """A process that reads from stdin and out using Twisted."""
  2. # Twisted Preamble
  3. # This makes sure that users don't have to set up their environment
  4. # specially in order to run these programs from bin/.
  5. import os
  6. import sys
  7. pos = os.path.abspath(sys.argv[0]).find(os.sep + "Twisted")
  8. if pos != -1:
  9. sys.path.insert(0, os.path.abspath(sys.argv[0])[: pos + 8])
  10. sys.path.insert(0, os.curdir)
  11. # end of preamble
  12. from zope.interface import implementer
  13. from twisted.internet import interfaces
  14. from twisted.python import log
  15. log.startLogging(sys.stderr)
  16. from twisted.internet import protocol, reactor, stdio
  17. @implementer(interfaces.IHalfCloseableProtocol)
  18. class Echo(protocol.Protocol):
  19. def connectionMade(self):
  20. print("connection made")
  21. def dataReceived(self, data):
  22. self.transport.write(data)
  23. def readConnectionLost(self):
  24. print("readConnectionLost")
  25. self.transport.loseConnection()
  26. def writeConnectionLost(self):
  27. print("writeConnectionLost")
  28. def connectionLost(self, reason):
  29. print("connectionLost", reason)
  30. reactor.stop()
  31. stdio.StandardIO(Echo())
  32. reactor.run() # type: ignore[attr-defined]