Results 1 to 10 of 13

Thread: Best approach for simple network game

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    TCP is connection-based. You establish a connection between two hosts, and then send data over that. The protocol guarantees that data arrives whole (any packets lost are automatically re-sent) and in order, but obviously, this comes at a price - managing and re-establishing the connection, re-sending the packets et cetera takes some time, so TCP is generally slower than UDP.

    UDP is connectionless. Kinda like snail-mail, you just slap an address on a packet and hurl it into the vast void of the network in hope that whatever intermediate servers will be able to successfully forward that to desired destination. Downside is that, obviously, the packets may get lost or arrive out of order. But this also an advantage - if you send player position data over the net, you always want the latest data. If an old packet gets lost anyhow, there's no need to resend, because you probably got fresher data, anyway. And if old data arrives later than newer data - you can insert a timestamp into packet data, then compare timestamps and ignore all old packets coming in.

    On LAN, TCP should suffice, as the ping on local network will most likely be <1ms anyway, and you get all that guaranteed data integrity benefits. Heck, on low ping networks you can even do this the archaic way: send player X packet to player Y, and don't advance the game for player X until he gets the packet from player Y.

  2. #2
    Nice to see this thread, as we will need it in a future project.

    BTW, I read about synapse at FPC wiki and I see this is a general-purpose networking library. Does nomebody made any gaming using it, or there's any tutorial about how to use it in games?
    No signature provided yet.

  3. #3
    Quote Originally Posted by Ñuño Martínez View Post
    Does nomebody made any gaming using it, or there's any tutorial about how to use it in games?
    I only made some simple demo for nxPascal on how to create server and client even in single Lazarus or Delphi application. It shows how to send custom binary packets or text messages. I have noticed small bugs in the code so expect them... not had motivation to do engine coding lately, especially with community engine coming up. For the main part it works well though, and i have done a small game test with 2 flying ships over Internet too.
    https://code.google.com/p/nxpascal/s...e/#svn%2Ftrunk
    nxNetwork in source and demos.

  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Nuno: I do use synapse in my projects that need network code (it even has serial support) which is really useful. If I recall, theres tutorials and documentation that is quite thorough in the source archive which I found sufficient to get going as I mentioned earlier. As for use in games - I have toyed with making a simple 2D MMORPG type engine and synapse worked wonders. Seeing as I did it just to see how hard it would be I got to the point where everything boots (server and client) and assets can be fetched/received from the server and data can be synced back and forth but beyond that it was pretty much just a question of content. What I can say is thats its a robust library that makes things very easy to code (said code was about a day and half of on/off lax development).

    If anyone has any queries, I'll gladly help out if its something I ran into though nothing really comes to mind off the bat
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  5. #5
    I'll investigate, and may be make a simple game or something. Thank-you.
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •