|
Project Information
Featured
Downloads
Links
|
Version 0.4 is available - This version contains many breaking API changes from 0.3, please review the API documentation and examples. Designed primarily for use in cross-platform game development, legume provides non-reliable, reliable and in-order transmission of messages via UDP. The focus behind the features and design of legume:
An example client with an event handler: import legume
from time import sleep
def on_connected(sender, event_args):
print 'Connected to server'
client = legume.Client()
client.OnConnectRequestAccepted += on_connected
client.connect(('host.example.com', 4000))
while True:
client.update()
sleep(0.001)To define a new message, specify a MessageTypeID to uniquely identity that particular message structure, and a MessageValues dictionary (key=value, value=type): class PlayerJoin(legume.messages.BaseMessage):
MessageTypeID = 100
MessageValues = {
'player_name' : 'string 32', # 32 char ansi string
'player_model_id' : 'int',
'start_x' : 'float',
'start_y' : 'float'
}
class ChatMessage(legume.messages.BaseMessage):
MessageTypeID = 2
MessageValues = {
'from' : 'int',
'message' : 'varstring'
}Sending a message: msg = ChatMessage() msg.from.value = 1 msg.message.value = "Hello from the Internet!" server.send_message_to_all(msg, reliable=True)
|