net.client

class net.client.Client(host, port, size=8192, remote=None)[source]

Client connection handler. Serves as a basis for net.client.TCP and net.client.UDP.

Parameters:
  • host – Hostname or ip address
  • port – Port number or serivce name
  • size – Block read size
  • remotesocket.socket instance or None
Attribute async:
 

net.async.Async instance

Callback onConnect():
 

Callback if the client connects to its peer

Callback onDisconnect():
 

Callback if the client disconnects from its peer

Callback onError(error):
 

Callback if an error occurs

Callback onReceive(data):
 

Callback if data is received from the peer

Callback onSend(data):
 

Callback if data is sent to the peer

connect()[source]

Connect to the remote address.

disconnect()[source]

Disconnect the client socket.

send(data)[source]

Send data to the client socket.

Parameters:
  • data – bytes to send
write(data)

Send data to the client socket.

Parameters:
  • data – bytes to send
class net.client.TCP(host, port, size=8192, remote=None, protocol='line', *args, **kwargs)[source]

TCP client implementation:

>>> with TCP('127.0.0.1', 80, protocol='line', collect=True) as http:
...     print >>http, 'GET / HTTP/1.1'
...     print >>http, 'Host: localhost'
...     print >>http, ''
...     for line in http:
...         print line
...
'HTTP/1.1 200 OK'
...
Parameters:
  • host – Server hostname or ip address
  • port – Server port or service name
  • size – Block read size
  • remotesocket.socket instance or None
  • protocol – Server protocolcol name or net.protocol.Protocol instance
  • args – Arguments for the server protocolcol class
  • kwargs – Keyword arguments for the server protocol class
class net.client.UDP(host, port, protocol='echo', *args, **kwargs)[source]

UDP client implementation:

>>> with UDP('127.0.0.1', 'echo', protocol='echo') as echo
...     print >>echo, 'hello world'
...     for line in echo:
...         print line
...
'hello world'
Parameters:
  • host – Server hostname or ip address
  • port – Server port or service name
  • protocol – Server protocolcol name or net.protocol.Protocol instance
  • args – Arguments for the server protocol class
  • kwargs – Keyword arguments for the server protocol class

Previous topic

net.callback

Next topic

net.ip

This Page