In this module you’ll find all the network related implementation
New in version 0.6: The Network module.
The Broadcast UDP client thread class.
This class is a thread to serve as Pyevolve client on the UDP datagrams, it is used to send data over network lan/wan.
>>> s = Network.UDPThreadClient('192.168.0.2', 1500, 666)
>>> s.setData("Test data")
>>> s.start()
>>> s.join()
Parameters: |
|
---|
Close the internal socket
Get the data to send
Return type: | data to send |
---|
Returns the number of sent bytes. The use of this method makes sense when you already have sent the data
Return type: | sent bytes |
---|
Method called when you call .start() of the thread
Broadcasts the data
Set the data to send
Parameters: | data – the data to send |
---|
The UDP server thread class.
This class is a thread to serve as Pyevolve server on the UDP datagrams, it is used to receive data from network lan/wan.
>>> s = UDPThreadServer("192.168.0.2", 666, 10)
>>> s.start()
>>> s.shutdown()
Parameters: |
|
---|
Note
this thread implements a pool to keep the received data, the poolSize parameter specifies how much individuals we must keep on the pool until the popPool method is called; when the pool is full, the sever will discard the received individuals.
Closes the internal socket
Gets the current receive buffer size
Return type: | integer |
---|
Calls the socket recvfrom method and waits for the data, when the data is received, the method will return a tuple with the IP of the sender and the data received. When a timeout exception occurs, the method return None.
Return type: | tuple (sender ip, data) or None when timeout exception |
---|
Returns True when there is data on the pool or False when not
Return type: | boolean |
---|
Returns the size of the pool
Return type: | integer |
---|
Return the last data received on the pool
Return type: | object |
---|
Called when the thread is started by the user. This method is the main of the thread, when called, it will enter in loop to wait data or shutdown when needed.
Sets the receive buffer size
Parameters: | size – integer |
---|
Shutdown the server thread, when called, this method will stop the thread on the next socket timeout
The Unicast UDP client thread class.
This class is a thread to serve as Pyevolve client on the UDP datagrams, it is used to send data over network lan/wan.
>>> s = Network.UDPThreadClient('192.168.0.2', 1500)
>>> s.setData("Test data")
>>> s.setTargetHost('192.168.0.50', 666)
>>> s.start()
>>> s.join()
Parameters: |
|
---|
Set the data to send
Parameters: | data – the data to send |
---|
Close the internal socket
Returns True when there is data on the pool or False when not
Return type: | boolean |
---|
Returns the size of the pool
Return type: | integer |
---|
Return the last data received on the pool
Return type: | object |
---|
Method called when you call .start() of the thread
Send the data
Parameters: | data – the data to send |
---|---|
Return type: | bytes sent to each destination |
Sets multiple host/port targets, the destinations
Parameters: | address_list – a list with tuples (ip, port) |
---|
Set the host/port of the target, the destination
Parameters: |
|
---|
Note
the host will be ignored when using broadcast mode
Shutdown the server thread, when called, this method will stop the thread on the next socket timeout
Return all the IPs from current machine.
>>> Util.getMachineIP()
['200.12.124.181', '192.168.0.1']
Return type: | a python list with the string IPs |
---|
Pickles the object and compress the dumped string with zlib
Parameters: |
|
---|
Decompress a zlib compressed string and unpickle the data
Parameters: | obj – the object to be decompressend and unpickled |
---|