Module pyinsim :: Class InSim
[hide private]
[frames] | no frames]

Class InSim

source code

Class to manage an InSim connection with LFS.

Instance Methods [hide private]
 
__init__(self, conn=1, timeout=10.0, name='default')
Initialise the InSim object.
source code
string
getName(self)
Get the name of the InSim connection.
source code
 
setName(self, name)
Set the name of the InSim connection.
source code
 
setTimeout(self, timeout)
Set the UDP timeout.
source code
number
getTimeout(self)
Get the UDP timeout.
source code
boolean
isConnected(self)
Get if the socket is connected.
source code
 
connect(self, host='localhost', port=29999, blocking=False)
Connect to InSim on the specified host and port.
source code
 
close(self)
Close the InSim connection.
source code
 
__close(self)
Internal close which does not raise an InSimClosed event.
source code
 
send(self, packetType, **values)
Send a packet to InSim.
source code
 
sendB(self, data)
Send raw binary data to InSim.
source code
 
sendP(self, *packets)
Send one or more packets to InSim.
source code
 
__receiveThread(self)
The internal receive thread.
source code
 
onPacketReceived(self, data)
Virtual method called when a packet is received.
source code
 
__keepAlive(self, packetType, data) source code
 
run(self)
Block the calling thread until the InSim connection has closed.
source code
 
onInSimEvent(self, evtType, args)
Virtual method called when an InSim event is raised.
source code
 
bind(self, evtType, callback, customPacket=None)
Bind a packet callback event-handler.
source code
 
unbind(self, evtType, callback)
Unbind a packet callback event-handler.
source code
boolean
isBound(self, evtType, callback)
Get if a specific event-handler has been bound.,
source code
 
raisePacketEvent(self, *packets)
Raise a packet event as if the packet was received through InSim.
source code
Method Details [hide private]

__init__(self, conn=1, timeout=10.0, name='default')
(Constructor)

source code 

Initialise the InSim object.

Parameters:
  • conn (enum) - Type of connection, either INSIM_TCP or INSIM_UDP.
  • timeout (number) - Seconds to wait before timing out in UDP mode.
  • name (string) - An optional name for the connection.

getName(self)

source code 

Get the name of the InSim connection.

Returns: string
Name of the connection.

setName(self, name)

source code 

Set the name of the InSim connection.

Parameters:
  • name (string) - Name of the connection.

setTimeout(self, timeout)

source code 

Set the UDP timeout.

Parameters:
  • timeout (number) - The timeout seconds.

getTimeout(self)

source code 

Get the UDP timeout.

Returns: number
The timeout seconds.

isConnected(self)

source code 

Get if the socket is connected.

Returns: boolean
True if the socket is connected.

connect(self, host='localhost', port=29999, blocking=False)

source code 

Connect to InSim on the specified host and port.

Known Issues: In UDP mode no exception is raised if the connection to InSim fails, but instead an EVT_ERROR is raised after the first packet is sent.

Parameters:
  • host (string) - Host where LFS is running.
  • port (number) - Port to connect to LFS through.

close(self)

source code 

Close the InSim connection. Sends a TINY_CLOSE before releasing the socket.

send(self, packetType, **values)

source code 

Send a packet to InSim.

>>> # Example.
>>> InSim.send(ISP_ISI, ReqI=1, Admin='password', IName='example')
Parameters:
  • packetType (enum) - Type of packet to send, from the ISP_ enumeration.
  • values (args) - Values to initialise the packet with.

sendB(self, data)

source code 

Send raw binary data to InSim.

Parameters:
  • data (string) - The data to send, as a binary formatted string.

sendP(self, *packets)

source code 

Send one or more packets to InSim.

Parameters:
  • packets (list) - A list of packets to send.

onPacketReceived(self, data)

source code 

Virtual method called when a packet is received. Handles the keep alive pulse and raises packet events.

Parameters:
  • data (string) - Packet data as a binary formatted string.

onInSimEvent(self, evtType, args)

source code 

Virtual method called when an InSim event is raised.

Parameters:
  • evtType (enum) - The type of event to raise an event for.
  • args (args) - Event arguments.

bind(self, evtType, callback, customPacket=None)

source code 

Bind a packet callback event-handler.

Parameters:
  • evtType (enum) - Type of evt to bind.
  • callback (function) - Function to call when the event is raised.
  • customPacket (object) - A custom packet object to use when unpacking packet data.

unbind(self, evtType, callback)

source code 

Unbind a packet callback event-handler.

Parameters:
  • evtType (enum) - Type of event to unbind.
  • callback (function) - Event-handler to unbind for this packet type.

isBound(self, evtType, callback)

source code 

Get if a specific event-handler has been bound.,

Parameters:
  • evtType (enum) - Event type to check for.
  • callback (function) - Callback to check for.
Returns: boolean
True if the event-handler has been bound.

raisePacketEvent(self, *packets)

source code 

Raise a packet event as if the packet was received through InSim. Useful for testing and debugging.

Parameters:
  • packets (list) - A list of packets to raise events for.