| Home | Trees | Indices | Help |
|
|---|
|
|
object --+
|
netshared.NetworkEndpoint --+
|
object --+ |
| |
metrics.Metrics --+
|
Client
A `Client` manages the connection to a `Server` instance elsewhere.
Creating an instance of a `Client` and connecting to a server is done
as shown in the minimalist example below::
client = Client()
# Server is running on localhost port 9000
client.connect(('localhost', 9000))
# This loop ensures that .update() is called.
while True:
client.update()
# Add a small time delay to prevent pegging the CPU.
time.sleep(0.0001)
The `Client` has a number of events that can be hooked into that provide
notifications of data sent from the server and state changes. An event
consists of the sender and the argument(in the example below, this
is the message), eg::
def my_message_handler(sender, message):
print "The greeting reads: %s" % message.greeting.value
my_client.OnMessage += my_message_handler
For the `Client.OnMessage` handler example above the argument part of the
event received is a re-assembled instance of the message that was sent, and
the greeting field in the message is obtained via
the fields `value` attribute.
* `Client.OnConnectRequestAccepted` - Fired when a `Client.connect` request
has been responded to by the server allowing the connection.
* `Client.OnConnectRequestRejected` - Fired when a `Client.connect` request
has been responded to by the server deneying the connection.
* `Client.OnMessage` - Fired when a message is receieved from the server.
See above example.
* `Client.OnError` - An error has occured. The event argument is a string
detailing the error.
* `Client.OnDisconnect` - The connection was gracefully closed by the
Server. If the connection was severed due to a time-out, the
`Client.OnError` event would fire.
| Instance Methods | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from |
|||
| Class Variables | |
CONNECTED = 104
(Inherited from legume.netshared.NetworkEndpoint)
|
|
CONNECTING = 103
(Inherited from legume.netshared.NetworkEndpoint)
|
|
DISCONNECTED = 100
(Inherited from legume.netshared.NetworkEndpoint)
|
|
ERRORED = 101
(Inherited from legume.netshared.NetworkEndpoint)
|
|
LISTENING = 102
(Inherited from legume.netshared.NetworkEndpoint)
|
|
MTU = 1400
(Inherited from legume.netshared.NetworkEndpoint)
|
|
| Properties | |
|
connected Returns True if this endpoint's state is `CONNECTED`. |
|
|
disconnected Returns True if this endpoint's state is `DISCONNECTED`. |
|
|
errored Returns True if this endpoint's state is `ERRORED`. |
|
|
is_server Returns false. |
|
|
latency Round-trip latency in ms |
|
|
out_buffer_bytes Count of bytes waiting to be transmitted on the wire. |
|
|
pending_acks Packets that have not yet been acknowledged. |
|
|
in_bytes Count of bytes received (header + data). |
|
|
out_bytes Count of bytes recieved (header + data). |
|
|
in_packets Count of packets received. |
|
|
out_packets Count of packets sent. |
|
|
keepalive_count Count of keep-alive Ping or Pong messages sent/received. |
|
|
reorder_queue Number of out-of-order messages received that are waiting to be inserted into the message stream. |
|
| OnConnectRequestRejected | |
| OnMessage | |
| OnConnectRequestAccepted | |
| OnError | |
| OnDisconnect | |
|
in_messages Count of messages received. (Inherited from legume.metrics.Metrics) |
|
|
out_messages Count of messages sent. (Inherited from legume.metrics.Metrics) |
|
| socket (Inherited from legume.netshared.NetworkEndpoint) | |
| state (Inherited from legume.netshared.NetworkEndpoint) | |
| timeout (Inherited from legume.netshared.NetworkEndpoint) | |
|
Inherited from |
|
| Method Details |
Create a Client endpoint. A Client is initially in the closed state
until a call to `connect`.
A messages factory is required to assemble and disassemble messages for
pushing down the intertubes to the server endpoint. If a
message_factory is not explicitly specified then the global
message_factory will be used.
:Parameters:
message_factory : `MessageFactory`
A message factory.
|
Initiate a connection to the server at the specified address.
This method will put the socket into the `CONNECTING` state. If a
connection is already established a ClientError exception is raised.
:Parameters:
address : (host, port)
Host address. An ArgumentError exception will be raised for
an invalid address.
|
Gracefully disconnect from the host. A disconnection packet is sent to the server upon calling the .update() method. The connection status of the class instance will not changed to `DISCONNECTED` until .update() is called. |
Send a message to the server. The message is added to the output buffer.
To flush the output buffer call the .update() method. If the client
is not connected to the server a `ClientError` exception is raised.
:Parameters:
message : `BaseMessage`
The message to be sent
|
Send a message to the server with guaranteed delivery. If the
client is not connected to the server a `ClientError` exception
is raised.
:Parameters:
message : `BaseMessage`
The message to be sent
|
| Property Details |
connectedReturns True if this endpoint's state is `CONNECTED`.
|
disconnectedReturns True if this endpoint's state is `DISCONNECTED`.
|
erroredReturns True if this endpoint's state is `ERRORED`.
|
is_serverReturns false.
|
latencyRound-trip latency in ms
|
out_buffer_bytesCount of bytes waiting to be transmitted on the wire.
|
pending_acksPackets that have not yet been acknowledged.
|
in_bytesCount of bytes received (header + data).
|
out_bytesCount of bytes recieved (header + data).
|
in_packetsCount of packets received.
|
out_packetsCount of packets sent.
|
keepalive_countCount of keep-alive Ping or Pong messages sent/received.
|
reorder_queueNumber of out-of-order messages received that are waiting to be inserted into the message stream.
|
OnConnectRequestRejected
|
OnMessage
|
OnConnectRequestAccepted
|
OnError
|
OnDisconnect
|
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Wed Jul 13 20:33:07 2011 | http://epydoc.sourceforge.net |