Hot answers tagged

10

After searching around, it seems that synchronizing the clocks of 2 or more computers is not a trivial task. A protocol like NTP does a good job but is supposedly slow and too complex to be practical in games. Also, it uses UDP which won't work for me because I'm working with web-sockets, which don't support UDP. I found a method here however, which seems ...


9

One of the most common misunderstandings of TCP vs UDP is that TCP's main feature is reliability. The main feature of TCP is that it abstracts a stream of data to send from one socket to another. Reliability, as provided by TCP is a requirement for the abstraction to work, but is not the central idea behind TCP. You might want to consider basing your ...


9

Part of this is a Technical solution, the other part is a Design solution. Peer to peer for this sort of thing has some fun drawbacks, especially as you're left with an interesting question of which client is authoritative, especially with lots of players. You can round robin between clients (this is actually useful for anti-cheating), but as everyone's ...


7

It turns out that this is due to how powersavings in mobile phones work. For my iPhone, sending a steady stream of UDP pings every 200 ms will keep the interface open, and give me a RTT of 80-100 ms. Reducing the ping frequency will drastically increase the RTT, to an average of about 400 ms. Further reducing frequency causes the RTT to occasionally go even ...


4

In most of cases the relationship is simple: Client -> Input to server Server -> Calculate logic and physics, send object position and property data back to client Client -> Render the scene using received data I guess that this is what you where asking for!;)


3

I'm thinking the clients will send data to a central server over a socket or http, and receive data via GCM push messaging. GCM push messaging strategy isn't appropriate for sending large amounts of data, for a few reasons: Rate limits are in place to prevent malicious or poorly coded apps from spamming an individual device with messages. Messages aren't ...


3

Those packets are still late. Even if you send 1M packets every second, there is still lag. Certain packet is packed at time t1 and it arrives at t1+ping/2. You send positions of other player to everyone. I assume you then do something like this: player[4].Position = new Vector2(readNextPlayerX(),ReadNextPlayerY()); You set that coordinate you sent, ...


2

I've written at length about this topic here: http://www.gabrielgambetta.com/fpm1.html. It's not exactly your case (this is for an authoritative server and dumb clients, vs your peer-to-peer architecture) but I guess the entity interpolation and server (in htis case, peer) reconciliation may apply.


2

UDP does not ensure that the package will arrive properly or that will arrive ordered, but is faster than TCP. TCP ensures the aforementioned features but is slower because of acks. Usually, action based games like FPS should use UDP because of the volume of data that must be sent/received over network. On the other hand, turn-based games should use TCP ...


2

Panda Pajamas excellent answer has covered a lot of the topic, but if you want more detailed information I suggest taking a look at Gaffer on Games series of blogs on 'UDP vs TCP'. There Glenn Fiedler goes into more detail about the problem with using TCP for games with real-time requirements, and suggests how you can build reliability into your own UDP-...


2

Figured out the problem: it was a remnant from a previous build in which I was trying to store all enemy data in variables and was not closing the registration of enemies properly: changed socket.on('enemyRegister', function(data){ // builds a monster on the client socket.broadcast.emit('enemyRegister', data); to socket.on('...


2

You have multiple problems with your current implementation. First of all, the biggest problem with peer-to-peer (or P2P for short) networking is, that it isn't designed for games. Due to it's nature, nobody has authority over the data being sent and received. If one of the players decides to cheat (always assume this), then there's nothing you can do ...


2

This is a good solution, since it allows both sides to know that their partner is alive. Call it "keepalive" or "hearbeat". Added benefit, when done frequently (1/sec) you can monitor lag / ping.


2

Running both TCP and UDP in parallel just leads to problems. Also, you might not need all the reliability features of TCP, so it might be overkill anyway. Most games solve this problem by replicating those TCP reliability features they really need on the application level. Do you have the concept of persistent connections? Add a connection-ID to every ...


1

Thanks for reading, turns out I just needed to spend a bit more time on my problem. For those who find this in the future, I used Kryonet to run my network code in a separate process.


1

I wrote an answer to a previous question about networking a multiplayer game here: How can I minimise data sent through a network in a modern FPS?. To summarize - we started with a system that read every single replicated field on every object and sent it to the client. This was slow, but once we had that working we knew we had a solid baseline for ...


1

You almost certainly do not want to update everything every single frame. Usually you would split data into Atomic events and Continuous events. So things like a position change would be a Continuous event and do not need to be handled immediately. For example you could send the new position every X milliseconds and the client could interpolate between ...


1

For what i can understand, i think you might could consider making a singelton factory that keeps your frame updates and the sends them over networking. so in theory what you do is that you have a gameobject, lets call it GMOBJ. so when you change your property somewhere in the code, you register this to the frameUpdater. frameUpdater.RegisterChange( GMOBJ,...


1

The target machine actively refusing the connection means that no one is listening on that port, so the target machine refused the connection. You'll need to verify that the server software you are trying to run is actually running and accepting connections.


1

Before answering, I tested your code in order to get your error, but it took too much time because of networking functions inside the loop - from 192.168.0.0 to 192.168.0.98 it took 25 minutes. This is an unacceptable waste of time, in my own opinion. I have a solution to your issue though, which involves a slight deeper knowledge of networking: ...


1

Unity has two different networking subsystems: The old but still available Legacy Networking API and the New UNET Networking API. But both are high-level APIs designed around the Unity engine and don't offer low-level TCP/IP functionality (both are based on UDP). That means you can't use them to interface with something not developed in or specifically for ...


1

I think really your question seems to be one of protocol rather than language. You've ruled out HTTP, but that doesn't necassarilly rule out PHP, as you can implement websockets in that as well as other languages. The same is also true of sockest, so if you know PHP my advice would be to stay with that language server side unless there's a compelling reason ...


1

The error is ambiguous, but from your phrasing, I think it is safe to say it is your use of threading. The error specifically notes "uncaught abort(-1)" error. In my experience, this tells us that something went wrong, but you need to do more digging to find out exactly what. It actually tells you this, in the actual error. Twice. See your browser'...


1

WebGl does not support threading currently. As for your error, I can't say what it is exactly. It's still tough to debug WebGL builds.


1

I think the main problem is that you try to send the whole game state every interval. A better way would be to split the sync into events and states. Events are important things like a spell that gets casted or damage that is dealt. Events need to get send over TCP because such packages are reliable and sequenced. States are components like the position and ...


1

JSON Philipp makes a good point about JSON. It is human readable and makes debugging network code easy. If you have no experience in programming network code, this would be the way to go. Yes, there is a lot of overhead by using JSON, but for small to medium data transfers, it should be more than enough. And like Alexandre Vaillancourt said, you can always ...


1

Basically, you cannot fix the [entire] world and, eventually, you will have to draw the line. If the server and all clients share the same frame-rate, they just need to synchronize upon connecting, and occasionally, thereafter, especially after a latency event. Latency does not affect the flow of time or the PC's ability to measure it so, in many cases, ...


1

The degree of access you are expecting may or may not be doable. However there is a simple callback function designed for sending messages from native plugins back to Unity: UnitySendMessage(). That will call the named method on the named object; in other words, you need to have an object with the desired method in the scene and then your plugin can call ...


1

In a project I once was involved (not game related) they decided to send each UDP message twice to reduce losses with an event id so if both messages were received the receiver could ignore the second, sounds basic but it did the trick. first define burst: shotgun and sniper has a burst of one bullet smg has a burst of 5 (?!) for each bullet send a UDP, ...


Only top voted, non community-wiki answers of a minimum length are eligible