qubx :: sock :: Socket :: Class Socket
[hide private]
[frames] | no frames]

Class Socket

source code

object --+
         |
        Socket
Known Subclasses:

Socket(host, port, async=True)

Common base class for sockets that communcate by structured blocks. e.g. RemoteConnect. A Socket can manage its own reading-thread and enqueue messages for user-thread processing.

To specialize, override readMsg, sendMsg, msgNonNull, and msgIsNull.

Instance Methods [hide private]
 
__init__(host, port, async=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__del__(self) source code
 
recvMsg(self, block=True, timeout=None)
:
source code
 
readerThread(self) source code
 
stop(self)
If async, stops the reader thread.
source code
 
done(self)
Returns True if the socket is closed and rq is empty.
source code
 
readBlock(self, count)
Returns a block of count bytes as a string, or raises qubsock.Stop, or any relevant socket.error from select or recv.
source code
 
readLine(self, terminator='\n')
Returns the next line as a string, including the trailing terminator, or raises qubsock.Stop, or any relevant socket.error from select or recv.
source code
 
sendBlock(self, block)
Sends block as a string of bytes; returns True on success, False if the socket closed.
source code
 
msgNonNull(self)
Override this method to return a (simple) non-null message (for use as place-holder).
source code
 
msgIsNull(self, msg)
Override this method to return whether a message is null.
source code
 
sendMsg(self, msg)
Override this method to send a message out self.sock.
source code
 
readMsg(self)
Override this method to read a structured message using readBlock and return it.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  sock
a socket.socket
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(host, port, async=True)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

recvMsg(self, block=True, timeout=None)

source code 

:

 if async:
     return the next message from the queue, possibly blocking until timeout.
     if the timeout is reached, raise Queue.empty
 if not async:
     return readMsg()

readMsg(self)

source code 

Override this method to read a structured message using readBlock and return it. Returns a null message to indicate end-of-stream (handle all exceptions).