Functions classes¶
Every program needs to override two classes: ServerFunctions
and ClientFunctions
.
Both inherit from the base class Functions
. These classes define which functions are callable from the remote side.
Usage examples:¶
Version 1: Both classes in one file
interface.py
class ServerFunctions(net.ServerFunctions):
from Server import greet_client, server_faculty
class ClientFunctions(net.ClientFunctions):
from Client import client_faculty, client_func
Version 2: server and client files are split
Client.py
class ServerFunctions(net.ServerFunctions):
@staticmethod
def dummy_function(x, y): ...
class ClientFunctions(net.ServerFunctions):
@staticmethod
def client_function():
return client.client_function()
Server.py
class ServerFunctions(net.ServerFunctions):
@staticmethod
def dummy_function(x, y):
return server.dummy_function(x, y)
class ClientFunctions(net.ServerFunctions):
@staticmethod
def client_function(): ...
Version 2.1: server and client files are split + mix 1 and 2
Client.py
class ServerFunctions(net.ServerFunctions):
@staticmethod
def dummy_function(x, y): ...
class ClientFunctions(net.ServerFunctions):
from client import client_function
Server.py
class ServerFunctions(net.ServerFunctions):
from server import dummy_function
class ClientFunctions(net.ServerFunctions):
@staticmethod
def client_function(): ...
Which version to choose?¶
Version 1 is the preferred one because you only need to change one file, when you add/change a function.
Version 2 may be necessary when you don`t have the source code of the other side available, only the function names. This version might be useful for documentation all functions.
Version 2.1 is a bit less work, than Version 2, because not every function needs to be redefined.