Home
Ratchet Library :: API Reference
API  ·  Manual

Module ratchet.socketpad

The socketpad library provides a layer on top of the ratchet.socket library to manage buffered socket IO. This allows for more familiar usages and easier implementation of binary and ASCII socket protocols. These functions can fail, see error handling section in manual for details.

Functions

close (self) Calls close() on the underlying socket, provided purely as convenience.
new (socket) Returns a new socketpad object, using the given socket as the underlying engine to send and receive buffered IO.
recv (self, stop) Attempts to receive a specific amount of data from the socket, receiving packets on the underlying socket until the criteria is met.
send (self, data, more) Adds the given data to the send-buffer, and possibly flushes it to the underlying socket.


Functions

close (self)
Calls close() on the underlying socket, provided purely as convenience.

Parameters

  • self: the socket object.
new (socket)
Returns a new socketpad object, using the given socket as the underlying engine to send and receive buffered IO. The socket object is available in raw form as the "socket" field of the returned socketpad object.

Parameters

  • socket: A socket object to buffer.

Return value:

a new socketpad object.
recv (self, stop)
Attempts to receive a specific amount of data from the socket, receiving packets on the underlying socket until the criteria is met.

Parameters

  • self: the socket object.
  • stop: if given as a number, this method will attempt to receive that many bytes on the socket and return exactly that many. If given as a string, the socket will receive until that string is seen, everything up-to and including that string is returned.

Return value:

string of data received on the socket. As with regular socket recv(), this method can return an empty string signaling the connection has been closed remotely.
send (self, data, more)
Adds the given data to the send-buffer, and possibly flushes it to the underlying socket.

Parameters

  • self: the socketpad object.
  • data: a string of data to send.
  • more: flag specifying more data will be buffered, so the send-buffer will not be flushed until this parameter is false.