6.25. foundations.tcpServer

tcpServer.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines the TCPServer class and other helpers objects needed to run a Python socket server.

Others:

6.25.1. Module Attributes

foundations.tcpServer.LOGGER

6.25.2. Classes

class foundations.tcpServer.EchoRequestsHandler(request, client_address, server)[source]

Bases: SocketServer.BaseRequestHandler

Defines the default echo requests handler.

handle()[source]

Reimplements the SocketServer.BaseRequestHandler.handle() method.

Returns:Method success.
Return type:bool
class foundations.tcpServer.TCPServer(address, port, handler=<class foundations.tcpServer.EchoRequestsHandler at 0x105fba2c0>)[source]

Bases: object

Defines a TCP server.

Initializes the class.

Usage:

>>> tcpServer = TCPServer("127.0.0.1", 16384)
>>> tcpServer.start()
True
>>> tcpServer.stop()
True
Parameters:
  • address (unicode) – Server address.
  • port (int) – Server port list.
  • handler – Request handler. ( SocketServer.BaseRequestHandler )
address[source]

Property for self.__address attribute.

Returns:self.__address.
Return type:unicode
port[source]

Property for self.__port attribute.

Returns:self.__port.
Return type:int
handler[source]

Property for self.__handler attribute.

Returns:self.__handler.
Return type:unicode
online[source]

Property for self.__online attribute.

Returns:self.__online.
Return type:unicode
start()[source]

Starts the TCP server.

Returns:Method success.
Return type:bool
stop(terminate=False)[source]

Stops the TCP server.

Returns:Method success.
Return type:bool