Multiplayer Real Time Game

0 votes
I first time develop the Real Time Multiplayer Game using appwarp, I was using Japan server and my current location is in Malaysia, but i found that, every milisec i send out a message about the player location  and rotation, but sometime another client receive the message slow, anyone have idea about receive the message from server lag problem?
asked Jul 11, 2014 in AppWarp by admin (10 points)
recategorized Oct 26, 2014 by sushil

1 Answer

0 votes
Hey,

Latency depends on network. Latency is present on every network though it might be very low. But again that depends on the network you are using. AppWarp tries to reduce this latency as much as it can.

You can also try using UDP for sending messages. AppWarp supports sending messages over UDP through sendUDPUpdatePeers() method.
answered Jul 11, 2014 by Suyash Mohan (900 points)
Hi Suyash Mohan, thank for reply, i new in appwarp, can you explain more how to use sendUDPUpdatePeers method. As i dont know what to pass into the methold, as it require byte value. Thanks
as i want send a string that contain player position, how i going to send this message using the method? thanks
Hey,

Before using any UDP function you must initialize the UDP with initUDP() method. This will call the onInitUDPDone() method of ConnectionRequestListener. If the resultCode is Success in onInitUDPDone(), you can use UDP methods, else you will not be able to use UDP methods on that network.

sendUDPUpdatePeers() and sendUpdatePeers() requires an array of bytes. You will need to convert your message to binary format. Either you can convert your string messages into binary messages or instead of forming string messages for position and then converting again to binary messages you can directly convert your float values into bytes and form a binary message. You can google on how to convert a value into bytes in C#.

Thanks
Hi Suyash Mohan,
comparing sendUDPUpdatePeers() method, SendUpdatePeers() method, SendChat(msg) method and sendPrivateChat(name,msg) method, which faster?
Thanks.
Hey,

sendUDPUpdatePeers will be faster than SendChat because SendChat uses TCP and sendUDPUpdatePeers  uses UDP protocol. But you must remember UDP is an unreliable protocol. Messages like position can be sent on UDP because even if a message is missed, you will get new position in next message but messages like hitting another player or picking up some power should not be sent on UDP because if missed other players are not going to get it again.
why sometime using sendUDPUpdatePeers after a while will like disconnected(no more sending message), another player not receive the message(no move) anymore.
Are you getting onConnectDone callback whenever there is a disconnection? Does this happens only with UDP methods? Please also try some other methods like sendChat()
yes only happend udp method, no onConnectDone callback
Hi Suyash Mohan,
any idea how to solve the problem, when i using send UDPUpdatePeers after a while it will stop sending to another client? i use sendchat before, no such problem happend.
Thanks
Hey,

There can be an issue with your NAT. Unlike TCP connection which maintains a session, UDP connections don't maintain sessions. In UDP connections NAT plays an important role as it maintains the port to port mapping information.

Some NAT removes this port to port mapping from their table after few seconds which causes an issue, as the server is still sending response back to public port but NAT is not translating it back to original port.

We are working on this issue and will revert back to you on this thread, when we have solved this problem.
Hi Suyash Mohan,

what is the expected approach time to solve the problem?just asking :)
Hey,

We will solve this issue in next release of our SDK. Meanwhile you can continue your development with sendUpdatePeers instead of sendUDPUpdatePeers. sendUpdatePeers is similar to sendUDPUpdatePeers but it uses TCP instead of UDP. Also let us know if you face the same problem with sendUpdatePeers or not. This will also help us ensure that your problem was only because of your NAT.

Thanks
Hi Suyash Mohan,
I tested the sendUpdatePeers and SendChat no problem, just the sendudpupdatepeers have problem.

Thanks
Hey, We have updated our SDK with keep alive support for UDP. Now your UDP connection should not break after few minutes.

Here is the new Unity SDK https://github.com/shephertz/AppWarpUnity/tree/master/v1.7.4

Hope this will solve your problem :)
Hi Suyash Mohan,

I want to ask some additional question, which is what kind of "movement algorithm" to make the the character move smooth(other player avatar) in UNITY, as i pass the position and rotation through UDP, now i using
Vector3.Lerp(transform.position, position,Time.deltaTime*10);(position)
Quaternion.Slerp(transform.rotation, target, Time.deltaTime*20);(rotation)
but the result is not synchronize, any suggestion to improve?, thanks
Hi Suyash Mohan,

I try the new sdk, and it solve the UDP problem, but when i use my ipad to test sendchat to another client for a around 2-3min, after that the player(ipad) disconnect from the server, and i try use unity to test the send chat, it work fine, any idea what cause this problem?
On mobile devices, network sometimes breaks when your network changes between 2G, 3G or Wifi.

To handle these situations we provide a connection resiliency feature. With connection resiliency if there is a connection error, you can recover your connection. You can read more about it here http://appwarp.shephertz.com/game-development-center/connection-resiliency/
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...