Package i2p :: Module socket
[show private | hide private]
[frames | no frames]

Module i2p.socket

Emulation of Python socket module using SAM.
Classes
Socket A socket object.

Exceptions
BlockError Socket call would have blocked.
ClosedError A command was used on a socket that closed gracefully.
Error Base class for all SAM errors.
NetworkError Network error occurred within I2P.
Timeout Time out occurred for a socket which had timeouts enabled via a prior call to settimeout().

Function Summary
  resolve(host, samaddr)
Resolve I2P host name --> I2P Destination.
  socket(session, type, samaddr, **kwargs)
Create a new socket.

Function Details

resolve(host, samaddr='127.0.0.1:7656')

Resolve I2P host name --> I2P Destination. Returns the same string if host is already a Destination.

socket(session, type, samaddr='127.0.0.1:7656', **kwargs)

Create a new socket. Argument session should be a session name -- if the name has not yet been used, an I2P Destination will be created for it, otherwise, the existing Destination will be re-used. An empty session string causes a transient session to be created. Argument type is one of SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.

I2P configuration keyword arguments:
  • in_depth - depth of incoming tunnel (default 2)
  • out_depth - depth of outgoing tunnel (default 2)

A single session may be shared by more than one socket, if the sockets are the same type, and if the sockets are created within the same Python process. The socket objects are multithread-safe.

Examples:
>>> a = i2p.socket('Alice', i2p.SOCK_STREAM)
>>> b = i2p.socket('Bob',   i2p.SOCK_DGRAM,
in_depth=2, out_depth=5)
The created object behaves identically to a socket from module socket, with the following exceptions:
  • I2P Destinations are used as address arguments [1].
  • bind is a no-op: sockets are always bound.
  • send* methods send all data and are non-blocking.

A given session name can only be open in a single Python program at a time. If you need to overcome this limitation, consider patching I2P.

[1]. Alternatively, a host name can be used as an address. It will be resolved using hosts.txt.

For details on how to use socket objects, see http://www.python.org/doc/current/lib/socket-objects.html

See the examples directory for code examples.

Generated by Epydoc 2.1 on Mon Aug 02 01:07:41 2004 http://epydoc.sf.net