Classes related to interprocess communications. More...
Classes | |
class | CommandClient |
Class to be used for sending commands. More... | |
class | CommandServer |
QTcpServer class used to receive commands and execute them. More... | |
class | CommandThread |
QThread class used to receive commands, try to execute and respond to them. More... | |
Functions | |
def | checkIPIsValid (ip) |
Method used to check a selected IP is possible to use with a Qt's QHostAddress. More... | |
def | startServer (addr, port) |
Method used to try to start a CommandServer at a valid IP address and port. More... | |
def | sendClientCommand (host, port, cmd, wait_time=WAIT_TIME_MS) |
Method to be used for sending commands. More... | |
Variables | |
int | SIZEOF_UINT16 = 2 |
Size of uint16 in bytes used to leave space at the beginning of each message to specify tcp message length (maximal length is 65535 bytes). More... | |
int | SERVER_ERROR_INVALID_ADDRESS = 1 |
Error code used in startServer() when trying to connect CommandServer to an invalid address. More... | |
int | SERVER_ERROR_PORT_OCCUPIED = 2 |
Error code used in startServer() when trying to connect CommandServer to an occupied port. More... | |
int | WAIT_TIME_MS = 30000 |
Time to wait in milliseconds - used to wait for incoming message etc. More... | |
string | COMMAND_EXECUTED_CONFIRMATION_MESSAGE = "Command executed successfully" |
Message send from a CommandServer to a CommandClient.sendCommand() or sendClientCommand() after successful execution of a command. More... | |
int | CLIENT_COMMAND_EXECUTED = 0 |
CommandClient.sendCommand() or sendClientCommand() return value after confirmation of successful command execution. More... | |
int | CLIENT_COMMAND_FAILED = 1 |
CommandClient.sendCommand() or sendClientCommand() return value if command execution failed (invalid command string). More... | |
int | CLIENT_ERROR_RESPONSE_NOT_COMPLETE = 2 |
CommandClient.sendCommand() or sendClientCommand() error code to signal that response was no received complete. More... | |
int | CLIENT_ERROR_NO_RESPONSE = 3 |
CommandClient.sendCommand() or sendClientCommand() error code to signal that no response from CommandServer was received. More... | |
int | CLIENT_ERROR_BLOCK_NOT_WRITTEN = 4 |
CommandClient.sendCommand() or sendClientCommand() error code to signal that message block was not written to a TCP socket. More... | |
int | CLIENT_ERROR_NO_CONNECTION = 5 |
CommandClient.sendCommand() or sendClientCommand() error code to signal that connection a host CommandServer was not established. More... | |
Classes related to interprocess communications.
The Classes in this module...
def communication.checkIPIsValid | ( | ip | ) |
Method used to check a selected IP is possible to use with a Qt's QHostAddress.
The IP can be either IPv4 address or *"localhost"* string with possible capital letters anywhere. IPv6 is not supported for now.
ip | A str with an IP address selected. |
Definition at line 244 of file communication.py.
def communication.sendClientCommand | ( | host, | |
port, | |||
cmd, | |||
wait_time = WAIT_TIME_MS |
|||
) |
Method to be used for sending commands.
This method is an alternative to using CommandClient
. It does not print any logs, just returns a value saying how the execution went.
To send a command using this method do: sendClientCommand("127.0.0.1",54333, "FreeCAD.Console.PrintWarning('Hello World\\n')")
cmd | A str command to be executed. |
host | A QtHostAddress to the CommandServer . |
port | An int of port at which CommandServer is listening. |
wait_time | An int setting milliseconds to wait for connection or message. |
CLIENT_COMMAND_EXECUTED
if all went great and command was executed. CLIENT_COMMAND_FAILED
if cmd
execution failed. CLIENT_ERROR_RESPONSE_NOT_COMPLETE
if a response received was incomplete. CLIENT_ERROR_NO_RESPONSE
if there was no response within WAIT_TIME_MS
. CLIENT_ERROR_BLOCK_NOT_WRITTEN
if communication failed during sending. CLIENT_ERROR_NO_CONNECTION
if no connection to a host was established. Definition at line 483 of file communication.py.
def communication.startServer | ( | addr, | |
port | |||
) |
Method used to try to start a CommandServer
at a valid IP address and port.
This method checks that a chosen addr
is valid IP address to be used to create Qt's QHostAddress using checkIPIsValid()
. If the IP address is valid, then a CommandServer
instance is created and tried to be made listen at selected addr
and port
. If it fails, then the used port had to be occupied.
addr | A str with a valid IPv4 Address or *"localhost"*. |
port | An int selecting a port to be used for the CommandServer . |
ERROR_INVALID ADDRESS
or ERROR_PORT_OCCUPIED
) or a CommnadServer instance if everything went hunky-dory. Definition at line 273 of file communication.py.
int communication.CLIENT_COMMAND_EXECUTED = 0 |
CommandClient.sendCommand()
or sendClientCommand()
return value after confirmation of successful command execution.
Definition at line 65 of file communication.py.
int communication.CLIENT_COMMAND_FAILED = 1 |
CommandClient.sendCommand()
or sendClientCommand()
return value if command execution failed (invalid command string).
Definition at line 69 of file communication.py.
int communication.CLIENT_ERROR_BLOCK_NOT_WRITTEN = 4 |
CommandClient.sendCommand()
or sendClientCommand()
error code to signal that message block was not written to a TCP socket.
Definition at line 81 of file communication.py.
int communication.CLIENT_ERROR_NO_CONNECTION = 5 |
CommandClient.sendCommand()
or sendClientCommand()
error code to signal that connection a host CommandServer
was not established.
Definition at line 85 of file communication.py.
int communication.CLIENT_ERROR_NO_RESPONSE = 3 |
CommandClient.sendCommand()
or sendClientCommand()
error code to signal that no response from CommandServer
was received.
Definition at line 77 of file communication.py.
int communication.CLIENT_ERROR_RESPONSE_NOT_COMPLETE = 2 |
CommandClient.sendCommand()
or sendClientCommand()
error code to signal that response was no received complete.
Definition at line 73 of file communication.py.
string communication.COMMAND_EXECUTED_CONFIRMATION_MESSAGE = "Command executed successfully" |
Message send from a CommandServer
to a CommandClient.sendCommand()
or sendClientCommand()
after successful execution of a command.
Definition at line 61 of file communication.py.
int communication.SERVER_ERROR_INVALID_ADDRESS = 1 |
Error code used in startServer() when trying to connect CommandServer to an invalid address.
Definition at line 50 of file communication.py.
int communication.SERVER_ERROR_PORT_OCCUPIED = 2 |
Error code used in startServer() when trying to connect CommandServer to an occupied port.
Definition at line 54 of file communication.py.
int communication.SIZEOF_UINT16 = 2 |
Size of uint16 in bytes used to leave space at the beginning of each message to specify tcp message length (maximal length is 65535 bytes).
Definition at line 46 of file communication.py.
int communication.WAIT_TIME_MS = 30000 |
Time to wait in milliseconds - used to wait for incoming message etc.
Definition at line 57 of file communication.py.