Sign In Register

How can we help you today?

Start a new topic
Answered

Sending data to server and back.

 Hi, im making a realtime multiplayer in Unreal Engine, but can't find a solution, how can i send data to server and then emidiatly recieve that data on all client including sender?


Best Answer

Why do you want the player to receive the same data they sent? They can just use the data locally. 

If you really want to, and I don't think is a good idea, to send to the same player then you need to use RT Scripts like I showed up above.


-Send packet to server

-Let server send to all clients.


Again, what point in client sending data to server and receiving them? You're wasting bandwidth and potentially will lose packets and not see the effect reflected in game.


Cheers,
Omar


The send function automatically sends the packet to the server and to other clients in the session but not to the player sending it.

 

If you want to send a packet to the server and have the server send it to everybody then:

 

1- When sending the packet, the peers int array should have the int 0 in it. 0 is the address of the server. With any OpCode, for this example it'll be 99.

2- In your match's RT Script:

 

  

RTSession.onPacket(99, function(packet){
RTSession.newPacket().setData(packet.getData()).setOpCode(100).setTargetPeers().send();
} 

  

 

100 being an example OpCode. If you don't set the setTargetPeers then the server will send that packet to everyone.

 

However, why would you want to send the player the same packet they sent to the server? What are you trying to do?

 

Cheers,

Omar

 Its kind of a turn based game where, both players can manipulate the same character in game. so i wat to send some input data to server and see the same result on both clients.

can it be done via blueprints only, or i should write some scripts on cloud code?

 When sending data to server by seting 0 in the peers int, i did not recieve enithing on clients.

Hey, have you had a look at our RT example in the sample project?

It's got an example of how to do that. Here's a quick photo of sending an empty packet to all clients (Not including the sender).


tL-5fJjyi5wyrb0kdO70rBiu-QCPU69O1g.png


Cheers,

Omar


 Thanks Omar, Yes ive tried this method, but it seems to sends data to all peers exep for the sender.

Answer

Why do you want the player to receive the same data they sent? They can just use the data locally. 

If you really want to, and I don't think is a good idea, to send to the same player then you need to use RT Scripts like I showed up above.


-Send packet to server

-Let server send to all clients.


Again, what point in client sending data to server and receiving them? You're wasting bandwidth and potentially will lose packets and not see the effect reflected in game.


Cheers,
Omar

 Well thanks, i guess it was realy stupid idea to recieve the data that is already here)

Login to post a comment