Package legume :: Package udp :: Module client
[frames] | no frames]

Module 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.

Classes
ClientError
Client