Networking in SEGA

With SEGA, we strive to create highly distributed systems. Each component will theoretically be able to run on a different node on the network.

Networking component

The network relay is the only component that is in direct connection with the simulation. Other low level components connect to the network relay and tell the network relay what type of messages they would like to recieve. (The sonar network does not want laser sensor information, but it does want sonar sensor information)

Components that connect to the network relay are:

Networking abstraction

The networking code abstracts all the common and uncommon networking problems that all the other code should not be bothered with. It automatically reconnects, and sending data can be done as any native type.

Data sent and received by component is buffered by a Client object. A component should ensure it is capable of receiving and processing data in real time, or the buffers may become full and performance may be degraded.

Networking library

class networking.Client

Socket buffering and reconnection handler

send(command, params=None)
Queue data for sending. The command is a string describing the action, with optional parameters (usually a dictionary or list).
class networking.EventDriver

Event based networking

acceptConnection(client)
Called when a new client connection has been accepted from listen socket
connect(address, handler, label=None, protocol=<class 'networking.PickleProtocol'>)
Establish non-blocking connection to a remote host. Handler is an instance that handles events for the socket. Label defines a friendly name for the socket. Protocol determines the message format sent over the wire.
disconnect(sock, ignoreReconnect=True)
Disconnect and remove socket. If ignoreReconnect is true, the socket is not automatically reconnected.
listen(address, handler, label=None, protocol=<class 'networking.PickleProtocol'>)
Create listen socket. Handler is an instance that handles events for the socket. Label defines a friendly name for the socket. Protocol determines the message format sent over the wire.
poll()
Poll the currently active network connections
tick()
Tick is executed after polling to perform idle work.
class networking.PickleProtocol

Pickle based protocol for internal communication

static deserialize(data)
Unpickles a Python object
static makePacket(command, params)
Create a packet
static parsePacket(data)
Parse data and return packet
static serialize(obj)
Pickles a Python object
class networking.USARSimProtocol

Parser for USARSim protocol

static deserialize(data)
Parse a set of message tokens into a list of lists. Assumes format: {key1 value1 key2 value2 ... keyN valueN} – all separated by spaces
static makePacket(command, parameters)
Create a packet
static parsePacket(data)
Parse data and return packet
static serialize(obj)
Convert Python objects into something USARSim can parse

Table Of Contents

Previous topic

Distributed components

Next topic

Low level components

This Page