net.server

class net.server.Server(host, port, size=8192)[source]

Server connection handler. Serves as a basis for net.server.TCP and net.server.UDP.

Parameters:
  • host – hostname or ip address
  • port – port number or serivce name
  • size – block read size
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

listen()[source]

Start listening for client connections.

class net.server.TCP(host, port, protocol='line', *args, **kwargs)[source]

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:
  • host – Server hostname or ip address
  • port – Server port or service name
  • size – Block read size
  • protocol – Server protocolcol name or net.protocol.Protocol instance
  • args – Arguments for the server protocolcol class
  • kwargs – Keyword arguments for the server protocol class

Previous topic

net.proto.http

Next topic

net.system

This Page