Home | Trees | Indices | Help |
---|
|
object --+ | Socket
Socket(family=PR_AF_INET, type=PR_DESC_SOCKET_TCP)
Create a new NSPR socket:
|
|||
|
|||
|
|||
a new object with type S, a subtype of T |
|
||
|
|||
(Socket, NetworkAddress) |
|
||
(Socket, NetworkAddress, buf) |
|
||
|
|||
|
|||
|
|||
integer |
|
||
NetworkAddress |
|
||
NetworkAddress |
|
||
|
|||
|
|||
file object |
|
||
the next value, or raise StopIteration |
|
||
|
|||
buf |
|
||
[buf] |
|
||
buf |
|
||
buf |
|
||
amount |
|
||
amount |
|
||
amount |
|
||
|
|||
|
|
|||
Socket |
|
||
(Socket, Socket) |
|
||
(flags, ...) |
|
|
|
|
|
The socket is a rendezvous socket that has been bound to an address with Socket.bind() and is listening for connections after a call to Socket.listen(). Socket.accept() accepts the first connection from the queue of pending connections and creates a new socket for the newly accepted connection. The rendezvous socket can still be used to accept more connections. Socket.accept() blocks the calling thread until either a new connection is successfully accepted or an error occurs. If the timeout parameter is not PR_INTERVAL_NO_TIMEOUT and no pending connection can be accepted before the time limit, Socket.accept() raises a nss.error.NSPRError exception with the error code PR_IO_TIMEOUT_ERROR. Socket.accept() returns a tuple containing a new Socket object and Networkaddress object for the peer.
|
Socket.accept_read() combines the behavior of Socket.accept() and Socket.recv(). It accepts a new connection and after it performs an initial read on the new socket as Socket.recv() would it returns the newly created Socket and NetworkAddress objects for the peer as well as a buffer of data. Socket.accept_read() returns a tuple containing a new Socket object, a new Networkaddress object for the peer, and a bufer containing data from the first read on the Socket object.
|
When a new socket is created, it has no address bound to it. Socket.bind() assigns the specified network address to the socket. If you do not care about the exact IP address assigned to the socket, create a NetworkAddress object using PR_INADDR_ANY. If you do not care about the TCP/UDP port assigned to the socket, set the port value of the NetworkAddress object to 0. Note that if Socket.connect() is invoked on a socket that is not bound, it implicitly binds an arbitrary address to the socket. Call Socket.get_sock_name to obtain the address (name) bound to a socket.
|
Socket.connect() is usually invoked on a TCP socket, but it may also be invoked on a UDP socket. Both cases are discussed here. If the socket is a TCP socket, Socket.connect() establishes a TCP connection to the peer. If the socket is not bound, it will be bound to an arbitrary local address. Socket.connect() blocks until either the connection is successfully established or an error occurs. If the timeout parameter is not PR_INTERVAL_NO_TIMEOUT and the connection setup cannot complete before the time limit, Socket.connect() fails with the error code PR_IO_TIMEOUT_ERROR. If the socket is a UDP socket, there is no connection setup to speak of, since UDP is connectionless. If Socket.connect() is invoked on a UDP socket, it has an overloaded meaning: Socket.connect() merely saves the specified address as the default peer address for the socket, so that subsequently one can send and receive datagrams from the socket using Socket.send() and Socket.recv() instead of the usual Socket.send_to() and Socket.recv_from().
|
The method return values varies depending on the option, see below:
|
|
|
|
|
|
|
|
Socket.recv() blocks until some positive number of bytes are transferred, a timeout occurs, or an error occurs. No more than amount bytes will be transferred. If the length of the returned buffer is 0 this indicates the network connection is closed.
|
Socket.recv_from() blocks until some positive number of bytes are transferred, a timeout occurs, or an error occurs. No more than amount bytes will be transferred. If the length of the returned buffer is 0 this indicates the network connection is closed. Note: Socket.recv_from() is usually used with a UDP socket.
|
Socket.send() blocks until all bytes are sent (unless the socket is in non-blocking mode), a timeout occurs, or an error occurs. In the case of a timeout or an error then a nss.error.NSPRError will be raised. The function returns the number of bytes actually transmitted.
|
Socket.send_to() blocks until all bytes are sent (unless the socket is in non-blocking mode), a timeout occurs, or an error occurs. In the case of a timeout or an error then a nss.error.NSPRError will be raised. The function returns the number of bytes actually transmitted. Note: Socket.send_to() is usually used with a UDP socket.
|
Socket.sendall() blocks until all bytes are sent (unless the socket is in non-blocking mode), a timeout occurs, or an error occurs. In the case of a timeout or an error then a nss.error.NSPRError will be raised. The function returns the number of bytes actually transmitted.
|
The method signature varies depending on the option, see below:
|
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 | http://epydoc.sourceforge.net |