TCP Client/Server Library:

Module import: from tcpcom import *

Class TCPServer

server = TCPServer(port, stateChanged, isVerbose = False) creates a TCP socket server that listens on TCP port for a connecting client. State changes are notified by the callback stateChanged(). For isVerbose = True, debug messages are written to output window
stateChanged(state, msg)

Callback called at state change events.
state: TCPServer.PORT_IN_USE, msg: port
state: TCPServer.CONNECTED, msg: IP address of client
state: TCPServer.LISTENING, msg: port
state: TCPSever.TERMINATED, msg: empty
state: TCPServer.MESSAGE, msg: message received from client (string)

server.disconnect() closes the connection with the client and enters the LISTENING state
server.isConnected() True, if a client is connected to the server
server.terminate() closes the connection and terminates the LISTENING state. Releases the IP port
server.isTerminated() True, if the server has been terminated
server.sendMessage(msg) sends the information msg to the client (as string, the character \0 (ASCII 0) serves as end of string indicator, it is transparently added and removed)
TCPServer.getVersion() returns the module version as string


Klasse TCPClient

client = TCPClient(ipAddress, port, stateChanged, isVerbose = False)

creates a TCP socket client prepared for a connection with a TCPServer at given address (string) and port (integer). State changes are notified by the callback stateChanged(). For isVerbose = True, debug messages are written to the output window

stateChanged(state, msg) Callback called at state change events.
state: TCPClient.CONNECTING, msg: IP address:port of server
state: TCPClient.CONNECTION_FAILED, msg: IP address:port of server
state: TCPClient.CONNECTED, msg: IP address:port of server
state: TCPClient.SERVER_OCCUPIED, msg: IP address:port of server
state: TCPClient.DISCONNECTED, msg: empty
state: TCPClient.MESSAGE, msg: message received from server (string)
client.connect() creates a connection to the server (blocking until timeout). Returns True, if the connection is established; otherwise returns False
client.connect(timeout) same, but with timeout (in s) to establish the connection
client.isConnecting() True during a connection trial
client.isConnected() True, if the client is connected to a server
client.disconnect() closes the connection with the server
client.sendMessage(msg, responseTime) sends the information msg to the server (as string, the character \0 (ASCII 0) serves as end of string indicator, it is transparently added and removed). For responseTime > 0 the method blocks and waits for maximum responseTime seconds for a server reply. Returns the message or None, if a timeout occured
TCPClient.getVersion() returns the module version as string

 

Bluetooth Client/Server Library

Module import: from btcom import *

class BTServer

server = BTServer(serviceName, stateChanged, isVerbose = False) creates a Bluetooth server that exposes the RFCOMM service with name serviceName. State changes are notified by the callback stateChanged(). For isVerbose = True, debug messages are written to the output window
stateChanged(state, msg)

Callback called at state change events.
state: "LISTENING" , msg: empty
state: "CONNECTED", msg: remote info: bluetooth name (MAC address)
state: "TERMINATED", msg: empty
state: "MESSAGE", msg: message received

server.disconnect() closes the connection with the client and enters the LISTENING state
server.isConnected() True, if a client is connected to the server
server.terminate() closes the connection and terminates the LISTENING state. Releases internal resources
server.isTerminated() True, if the server has been terminated
server.sendMessage(msg) sends the information msg to the client (as string, the character \0 (ASCII 0) serves as end of string indicator, it is transparently added and removed)
BTServer.getVersion() returns the module version as string


class BTClient

client = BTClient(stateChanged, isVerbose = False)

creates a Bluetooth client prepared for a connection with a
BTServer. State changes are notified by the callback stateChanged(). For isVerbose = True, debug messages are written to the output window

client.findServer(serverName, timeout) performs a device inquiry for the given server Bluetooth name. Returns the tuple serverInfo: ("nn:nn:nn:nn:nn:nn", channel) , e.g. ("B8:27:EB:04:A6:7E", 1). If the server is not found, None is returned. The search is repeated until the timeout (in s) is reached
client.findService(serviceName, timeout)

performs a service inquiry for a Bluetooth server exposing the given RFCOMM service. Returns the tuple serverInfo: ("nn:nn:nn:nn:nn:nn", channel) , e.g. ("B8:27:EB:04:A6:7E", 1). If the service is not found, None is returned. The search is repeated until the timeout (in s) is reached

stateChanged(state, msg) Callback called at state change events.
state: "CONNECTING" , msg: server info (MAC address, Bluetooth channel)
state: "CONNECTED" , msg: server info
state: "CONNECTION_FAILED", msg: sever info
state: "DISCONNECTED", msg: empty
state: "MESSAGE", msg: message received
client.connect(serverInfo, timeout) Performs a connection trial to the server with given serverInfo. If the connection trial fails, it is repeated until the timeout (in s) is reached. Returns True, if the connection is established; otherwise False is returned. serverInfo is a tuple with the MAC address and channel number ("nn:nn:nn:nn:nn:nn", channel) , e.g. ("B8:27:EB:04:A6:7E", 1)
client.isConnecting() returns True during the connection trial
client.isConnected() returns True,
client.disconnect() beendet die Verbindung mit dem Server
client.sendMessage(msg,) sendet die Information msg zum Server (als String, das Zeichen \0 (ASCII 0) dient als Endzeichen, automatisch transparent hinzugefügt und wieder entfernt).
BTClient.getVersion() returns the module version as string