Module tcpcom :: Class TCPServer
[frames] | no frames]

Class TCPServer

source code

        object --+        
                 |        
threading._Verbose --+    
                     |    
      threading.Thread --+
                         |
                        TCPServer
Known Subclasses:

Class that represents a TCP socket based server.

Instance Methods
 
__init__(self, port, stateChanged, endOfBlock='\x00', isVerbose=False)
Creates a TCP socket server that listens on TCP port for a connecting client.
source code
 
setTimeout(self, timeout)
Sets the maximum time (in seconds) to wait in blocking recv() for an incoming message.
source code
 
run(self)
Method representing the thread's activity.
source code
 
terminate(self)
Closes the connection and terminates the server thread.
source code
 
disconnect(self)
Closes the connection with the client and enters the LISTENING state
source code
 
sendMessage(self, msg)
Sends the information msg to the client (as String, the character endOfBlock (defaut: ASCII 0) serves as end of string indicator, it is transparently added and removed)
source code
 
isConnected(self)
Returns True, if a client is connected to the server.
source code
 
loopForever(self)
Blocks forever with little processor consumption until a keyboard interrupt is detected.
source code
 
isTerminated(self)
Returns True, if the server is in TERMINATED state.
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
debug(msg) source code
 
getVersion()
Returns the library version.
source code
 
getIPAddress() source code
Class Variables
  isVerbose = False
  PORT_IN_USE = 'PORT_IN_USE'
  CONNECTED = 'CONNECTED'
  LISTENING = 'LISTENING'
  TERMINATED = 'TERMINATED'
  MESSAGE = 'MESSAGE'
Properties

Inherited from threading.Thread: daemon, ident, name

Inherited from object: __class__

Method Details

__init__(self, port, stateChanged, endOfBlock='\x00', isVerbose=False)
(Constructor)

source code 

Creates a TCP socket server that listens on TCP port for a connecting client. The server runs in its own thread, so the constructor returns immediately. State changes invoke the callback onStateChanged().

Parameters:
  • port - the IP port where to listen (0..65535)
  • stateChange - the callback function to register
  • endOfBlock - character indicating end of a data block (default: '')
  • isVerbose - if true, debug messages are written to System.out, default: False
Overrides: object.__init__

setTimeout(self, timeout)

source code 

Sets the maximum time (in seconds) to wait in blocking recv() for an incoming message. If the timeout is exceeded, the link to the client is disconnected. (timeout <= 0: no timeout).

run(self)

source code 

Method representing the thread's activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Overrides: threading.Thread.run
(inherited documentation)

terminate(self)

source code 

Closes the connection and terminates the server thread. Releases the IP port.

sendMessage(self, msg)

source code 

Sends the information msg to the client (as String, the character endOfBlock (defaut: ASCII 0) serves as end of string indicator, it is transparently added and removed)

Parameters:
  • msg - the message to send

isConnected(self)

source code 

Returns True, if a client is connected to the server.

Returns:
True, if the communication link is established

isTerminated(self)

source code 

Returns True, if the server is in TERMINATED state.

Returns:
True, if the server thread is terminated

getVersion()
Static Method

source code 

Returns the library version.

Returns:
the current version of the library