New project checklist¶
This page contains a checklist with all necessary parts that you need, when you start a new project. This checklist assumes you know how to use the library and just need a short recapitulation. If not check out the Getting started page.
Install pynetworking
- Override classes:
2.1 ServerFunctions (Functions classes)
2.2 ClientFunctions (Functions classes)
2.3 ServerCommunicator (
ServerCommunicator
)2.4 ClientCommunicator (
ClientCommunicator
)
Start the server with
ClientManager
Start the client with created
ServerCommunicator
While you are working on your project, remember to add necessary functions to the Functions classes.
Minimal Code that can be copied¶
net_interface.py
import pynetworking as net
class ServerFunctions(net.ServerFunctions):
pass
# Import all Server functions here
# e.g. from server import function1
class ClientFunctions(net.ClientFunctions):
pass
# Import all Client functions here
# e.g. from client import function2
class ServerCommunicator(net.ServerCommunicator):
remote_functions = ServerFunctions
local_functions = ClientFunctions
class ClientCommunicator(net.ClientCommunicator):
remote_functions = ClientFunctions
local_functions = ServerFunctions
#: alias for all server functions
server = ServerCommunicator.remote_functions
def get_client() -> ClientCommunicator:
"""Main purpose is to supply better auto completions"""
return net.ClientManager().get()
client.py
import net_interface
address = ("127.0.0.1", 5000)
net_interface.ServerCommunicator.connect(address)
# Do more stuff
net_interface.ServerCommunicator.close_connection()
server.py
import net_interface
import multiprocessing
client_manager = net.ClientManager(address, net_interface.ClientCommunicator)
client_manager.start()
# Server is now started
#: One possible way to add an option to stop the server
queue = multiprocessing.Queue()
try:
while True:
msg = queue.get()
if msg == "stop":
break
finally:
client_manager.stop_listening()
client_manager.stop_connections()