socket_utils

Module: tools.socket_utils

Provide often needed functions when dealing with the Python socket module

** Functions **

receive:Return a full message read from a socket connection
inform:Send a message to a socket connection
talk:Send a message to a socket connection and return the answer
Author:Anett Seeland (anett.seeland@dfki.de)
Created:2012/08/28

Function Summary

receive(conn[, end_token]) Return a full message read from a socket connection
inform(to_send[, conn, ip_port]) Send a message and return the connection
talk(to_send[, conn, ip_port]) Send a message and return the answer and the connection

Functions

receive()

pySPACE.tools.socket_utils.receive(conn, end_token='!END!')[source]

Return a full message read from a socket connection

inform()

pySPACE.tools.socket_utils.inform(to_send, conn=None, ip_port=None)[source]

Send a message and return the connection

If an connection is already established, the message is send to it. If the connection is broken and the message cannot be sent, a new connection is created.

Parameters
to_send:A String representing the message to send.
conn:A client socket where the message is send to.
ip_port:A Tuple of IP and port for potentially reconnect.

One of the parameters conn or ip_port has to be specified.

talk()

pySPACE.tools.socket_utils.talk(to_send, conn=None, ip_port=None)[source]

Send a message and return the answer and the connection

If an connection is already established, the message is send to it and the answer is returned. If the connection is broken and the message cannot be sent, a new connection is created.

Parameters
to_send:A String representing the message to send.
conn:A client socket where the message is send to.
ip_port:A Tuple of IP and port for potentially reconnect.

One of the parameters conn or ip_port has to be specified.