In general this file is no good setup.
What do you expect an object that is called Server (or Client) is supposed to do?
Does it mean they establish a connection (client calls server)?
What happens after the connection is established?
What object should communicate with what other object? And should does it say? What should happen after communication?
Yes, you can have a single application that acts both as client and server at the same time, especially for testing. The questions remain the same.
I need to know:
A) what object sends what data to what other object?
B) what should the other object do with the received data?
I can see you wrote such code several times:
try:
Data, SRIP = GameLogic.sClient.recvfrom(1024)
UPData = pickle.loads(Data)
PosServer = [UPData[0],UPData[1],UPData[2]]
Server.worldPosition = PosServer
except OSError:
pass
A) it is a lot of code replication
B) it mixes business code and framework code together
Why is A) a problem? Imagine you need a change in the communication works … now think about how much work it is to update all these code locations.
How to solve it:
- place replicated code into a framework (function/module/package).
Why is B) a problem? And what is business and framework code?
Your business is that you want to copy the position of an object (master) to another object (slave).
Your framework transfers the necessary data.
Without network your framework would be just a variable e.g.
position = master.worldPosition
slave.worlPosition = position
it is so easy that you do not even think about it. But what if the slave is not available at that time?
then you need a frame work to carry the position to the slave.
position = master.worldPosition
transferPosition(position)
position = receivePosition()
slave.worlPosition = position
You see the business (copying position) is separated from framework. You do not even know how transferPosition() and receivePosition() work.
It could be this:
storage = {}
def transferPosition(position):
storage["position"] = position
def receivePosition():
return storage["position"]
or this
def transferPosition(position):
try:
...
server.sendTo(pickledPosition, ...)
except OSError:
...
def receivePosition():
try:
...
I hope you get the idea