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
A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are left.
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 |
---|
Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
Method called when you call .start() of the thread
Broadcasts the data
Set the data to send
Parameters: | data – the data to send |
---|
Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
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
A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are left.
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 |
---|
Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Returns True when there is data on the pool or False when not
Return type: | boolean |
---|
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
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
Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
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
A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are left.
Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Returns True when there is data on the pool or False when not
Return type: | boolean |
---|
Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
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
Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
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 |
---|