Control Swap

i created a client and server
the server have two objects that’s i can get access to control it [“Cube”] and [“Server”]
and the server have only one object that’s called [“Client”]
the proplem is when i run server the i controll the my objects the engine swaping the objects in the client screen
for example whe i click up arrow to move the [“Server”] object to up the [“Cube”] object who moves in the Client screen
and when i click w key to move [“Cube”] object to up the [“Server”] object who moves in the client screen

test(1).blend (370 KB)

I’m a bit confused.

your “Server” never waits for a connection.
Your “Client” never connects.

How do you transfer data without connection?

that’s are old video for how i connect the server with the client if that what you mean

You are right I didn’t knew that sendto() includes a connection.

Hint:
To investigate into your problem, I suggest you switch to wireframe mode before running your tests.

Analysis:

Your code is still confusing. When I isolate the creation of the sockets this is what remains:

client mode
-> send position of “Client”
-> receive position to be applied to “Server”

server mode
-> receive position to be applied to “Client”
-> send position to of “Server”.

What do you send? You always send a single position.
How do you know what position that is? Currently you interpret it in relation to the current “mode”. If the code runs in server mode you expect data for “Client”, if running in client mode you expect data for “Server”.

The data itself does not tell anything.

Now you bring in another object. Your sort of protocol does not cover that. You transfer one position, but you have three objects to apply it to.

As you mix business code (applying position) with framework code (transferring data) it makes it very hard for you to establish a useful structure.

Here are some thoughts:
A) Think about a protocol that tells what data you are transferring. Keep in mind: position, orientation, source object, several attributes in one message, several clients.
B) Sending messages is easy. You tell what you want to send (e.g. position of “Cube”).
C) Receiving messages is complex, as you rely on the message.
This can be:

  • network operation e.g. login, close
  • business operation e.g. position of “Cube”, orientation of “Camera”, deletion of “Wall”, creation of “Enemy”, player input “forward”
    You need to parse the message to separate network from business operations.
    You need to dispatch business operations, operate on the correct objects dependent on the message content.

I hope it helps somehow

I played around with an own network showcase. I quickly came to this questions:

A) what data do you want to transfer (e.g. object attributes)
B) how you want to apply transferred data to the receiving instance (what attributes, which object?)