Server connection handler. Serves as a basis for net.server.TCP and net.server.UDP.
| Parameters: |
|
|---|---|
| Attribute async: | |
net.async.Async instance |
|
| Callback onAccept(): | |
Callback if the server accepts a new client |
|
| Callback onListen(): | |
Callback if the server starts accepting clients |
|
| Callback onError(error): | |
Callback if an error occurs |
|
TCP server implementation:
>>> from net.async import start
>>> from net.server import TCP
>>> start(True)
>>> with TCP('localhost', 2266, protocol='echo') as echo:
... for peer in echo:
... print 'New peer:', peer
... print >>peer, 'Welcome to the net echo server'
...
Or using a more traditional Python syntax:
>>> server = TCP('localhost', 2266, protocol='echo')
>>> server.listen()
>>> for peer in server:
... print 'New peer:', peer
... peer.write('Welcome to the net echo server\n')
...
| Parameters: |
|
|---|