Skip to content

Update the simple server example code for py3 modern syntax #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ <h2>
</p>
<pre>
<code class="language-python" id="server">
from twisted.internet import protocol, reactor, endpoints
import math

from twisted.internet import protocol, endpoints, task

class Echo(protocol.Protocol):
def dataReceived(self, data):
Expand All @@ -190,8 +192,16 @@ <h2>
def buildProtocol(self, addr):
return Echo()

endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())
reactor.run()
async def echo_server(reactor):
await endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())
await task.deferLater(reactor, math.inf, lambda: pass)
return 0

def main():
return task.react(echo_server)

if __name__ == "__main__":
sys.exit(main())
</code>
</pre>
<p>
Expand Down