Home | Trees | Index | Help |
---|
Package i2p :: Module socket :: Class Socket |
|
Method Summary | |
---|---|
Equivalent to socket(). | |
Returns the original object. | |
Returns the original object. | |
Accept an incoming connection. | |
Does nothing. | |
Closes the socket. | |
Connect to a remote dest, identified in local SAM bridge's hosts file as host 'address'. | |
Like connect(), but return any error that is raised. | |
Get the remote Destination associated with the socket. | |
Get the local Destination associated with the socket. | |
Get the timeout value. | |
Listen for connections made to the socket. | |
Return a file object for the socket. | |
Receive string data from the socket. | |
Like recv(), but returns a tuple (data, remoteaddr), where data is the string data received, and remoteaddr is the remote Destination. | |
Sends string data to a remote Destination. | |
Identical to send(). | |
Send a packet to the given Destination. | |
Set blocking or non-blocking mode for the socket. | |
Set a timeout for the socket. | |
Raise an error if socket is not a connected stream socket. | |
Verify that the socket is not currently connected, and is not in the process of connecting. | |
Verify that the socket has not been closed. | |
Raise an error if socket is not a SOCK_STREAM. |
Property Summary | |
---|---|
dest : Local I2P Destination of socket | |
session : Session name | |
type : Socket type: SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW. |
Method Details |
---|
__init__(self,
session,
type,
samaddr='127.0.0.1:7656',
**kwargs)
Equivalent to socket().
|
__copy__(self)Returns the original object. |
__deepcopy__(self, memo)Returns the original object. |
accept(self)Accept an incoming connection. The socket must be type SOCK_STREAM, and listen() must be called prior to this command. The return value is (conn, remotedest), where conn is a new socket object made for the connection, and remotedest is the remote Destination from which the connection was made. Example:
>>> from i2p import socket
>>> s = socket.socket('Alice', socket.SOCK_STREAM)
>>> s.listen(10)
This prepares the server. Now accept an incoming connection:
>>> c, remotedest = s.accept()
>>> c.send('hello world!')
If accept() is called on a socket that is in non-blocking mode or
has a timeout, i2p.socket.BlockError or i2p.socket.Timeout may be
raised. This indicates that no incoming connection is currently
available.
|
bind(self, address)Does nothing. Provided for compatibility with the Python socket command bind(), which binds a server to a port. |
close(self)Closes the socket. It is an error to call any method other than recv() or recvfrom() on a closed socket. For streams, the receive methods return data that was received prior to the closing of the socket. For datagram and raw sockets, the receive methods cannot be used on a closed socket. |
connect(self, address)Connect to a remote dest, identified in local SAM bridge's hosts file as host 'address'. For example:
>>> s.connect('duck.i2p')
Alternatively, you can use a full base64 Destination: Example:
>>> s.connect('238797sdfh2k34kjh....AAAA')
If connect() is called on a socket that is in non-blocking mode or
has a timeout, i2p.socket.BlockError or i2p.socket.Timeout may be
raised. This indicates that the connection is still being initiated.
Use i2p.select.select() to determine when the connection is ready.
|
connect_ex(self, address)Like connect(), but return any error that is raised. Returns None if no error is raised. |
getpeername(self)Get the remote Destination associated with the socket. This is equivalent to s.remotedest, and is provided for compatibility with the Python socket module. |
getsockname(self)Get the local Destination associated with the socket. This is equivalent to s.dest, and is provided for compatibility with the Python socket module. |
gettimeout(self)Get the timeout value. |
listen(self, backlog)Listen for connections made to the socket. This method must be called before accept(). The backlog argument specifies the maximum number of queued incoming connections. |
makefile(self, mode='r', bufsize=-1)Return a file object for the socket. See socket.makefile() in the Python documentation for more information. |
recv(self, bufsize, flags=0)Receive string data from the socket. The maximum amount of data to be received is given by bufsize. If bufsize is zero, this function returns an empty string immediately. If bufsize is nonzero, this function blocks until at least one character is available for reading. If the socket has been closed, an empty string is returned as an end of file indicator. If recv() is called on a socket that is in non-blocking mode or has a timeout, i2p.socket.BlockError or i2p.socket.Timeout will be raised if data is not available within the given timeframe. For a datagram or raw socket, the first bufsize characters of the packet are read, and the remainder of the packet is discarded. To read the entire packet, use bufsize = -1. For datagram and raw sockets, the packet may originate from any Destination. Use recvfrom() with datagrams to determine the Destination from which the packet was received. The flags argument can be a bitwise OR of MSG_PEEK, MSG_WAITALL, and/or MSG_DONTWAIT. MSG_PEEK indicates that any data read should not be removed from the socket's incoming buffer. MSG_WAITALL indicates to wait for exactly bufsize characters or an error. MSG_DONTWAIT indicates that the recv() command should not block execution. |
recvfrom(self, bufsize, flags=0)Like recv(), but returns a tuple (data, remoteaddr), where data is the string data received, and remoteaddr is the remote Destination. |
send(self, string, flags=0)Sends string data to a remote Destination. For a stream, connect() must be called prior to send(). Once close() is called, no further data can be sent, and the stream cannot be re-opened. For datagram and raw sockets, connect() only specifies a Destination to which packets are sent to. send() will then send a packet to the given Destination. connect() can be used multiple times. The send() command never blocks execution. The flags argument is ignored. |
sendall(self, string, flags=0)Identical to send(). |
sendto(self, string, flags, address)Send a packet to the given Destination. Only valid for datagram and raw sockets. The address argument should be either a name from the hosts file, or a base64 Destination. The sendto() command never blocks execution. The flags argument is ignored. |
setblocking(self, flag)Set blocking or non-blocking mode for the socket. If flag is True, any method called on the socket will hang until the method has completed. If flag is False, all methods will raise i2p.socket.BlockError() if they cannot complete instantly. s.setblocking(False) is equivalent to s.settimeout(0); s.setblocking(True) is equivalent to s.settimeout(None). |
settimeout(self, value)Set a timeout for the socket. The value argument should be a timeout value in seconds, or None. None is equivalent to an infinite timeout. A socket operation will raise a i2p.socket.Timeout if the operation cannot complete within in the specified time limit. |
_verify_connected(self, needs_to_be_connected=True)Raise an error if socket is not a connected stream socket. |
_verify_not_connected(self)Verify that the socket is not currently connected, and is not in the process of connecting. |
_verify_open(self)Verify that the socket has not been closed. |
_verify_stream(self)Raise an error if socket is not a SOCK_STREAM. |
Property Details |
---|
destLocal I2P Destination of socket |
sessionSession name |
typeSocket type: SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW. |
Home | Trees | Index | Help |
---|
Generated by Epydoc 2.1 on Mon Aug 02 01:07:41 2004 | http://epydoc.sf.net |