Results 1 to 6 of 6

Thread: Need a little help with INDY

  1. #1

    Need a little help with INDY

    Hi I´m new to the forum but I have hanged around here for some time now, getting some inspiration and help. I´ve recently started with implementing some network code into my game-project with the INDY tcp components.

    I´ve managed to get a simple server-client dataflow, but if the client isnt running at the same computer as the server, the dataflow gets to slow and results in making the game sluggish for the client. I realize it is because I´m sending every variable by themself and send around 100 times per second.

    The basic setup that I want to work is just sending player cordinates in a 2d game with a decent fast rate.

    So my question is if someone could tell my how to write a good network code for a realtime network game with INDY and what i should think about when im writing the network code. I´m using Delphi 7.

    I should point out that I´m more or less a beginner at advanced pascal.

    Thanks for any help!

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,246
    Blog Entries
    2

    Need a little help with INDY

    Hi Brassawiking,

    I'm no expert at game related network coms, but I think one of the key things is to keep the amount of data you send small (less than 1024 bytes) so that it fits into one packet.

    Rather than send each item seperately, which may result in lots of packets, you could pack the data into a string.

    Code:
    function wordToString(data:word):string;
    begin
      result:=chr(data div 256)+chr(data mod 256);
    end;
    
    function stringToWord(srcData:string;startPos:integer):word;
    begin
      if &#40;length&#40;srcData&#41;<startPos+1&#41; then
        result&#58;=0
      else
        result&#58;=ord&#40;srcData&#91;startPos&#93;&#41;*256+ord&#40;srcData&#91;startPos+1&#93;&#41;;
    end;
    You can encode other values such as integer (although integer is trickier because of sign) in a similar manner. Then you can piece together a packet as a single string...

    Code:
      packet&#58;=wordToString&#40;playerX&#41;+wordToString&#40;playerY&#41;;
    At the other end, assuming this is the only data you send...

    Code:
      playerX&#58;=stringToWord&#40;packetData,1&#41;;
      playerY&#58;=stringToWord&#40;packetData,3&#41;;
    In doing this, you can send a single string. This will reduce the number of packets you send.

    I can't help further because as I say, I'm no expert. One place you could look is the Tutorials section.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3

    Need a little help with INDY

    Hi Athena!

    Thanks for the tip on formating the variables into a string. I will give that a try and see where it ends up .

  4. #4

    Need a little help with INDY

    Well I just jumped in to report that a single packet transport hit the nail right on . Thanks for the help Athena. I will make a post later about my game and introduce myself a bit better.

  5. #5
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,246
    Blog Entries
    2

    Need a little help with INDY

    Glad it helped. Theres a lot more to creating a good network transport protocol though. Like I said, I'm no expert, most of my serialised data transfers have been done at work using RS-232/RS-485 and a derivative of the HDLC protocol, so its far from optimal for network transfers.

    When the rest of the site is back online there are various articles about network programming, so you may want to have a nose through them.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  6. #6

    Need a little help with INDY

    Another trick is to send the data not that often, but let the "client" calculate the new "positions" etc. by the last known values.
    This is very useful if the client has to get values from many other mobile units (or players) via network.
    When new packets arrive the actual values and positions are updated. There is really no need to send X and Y positions 100 times a second. send it e.g. 20 times and calculate the values between by the last known speed and angle. You can see this in recent games, for example "World of Warcraft". When a player gets a "lag" or disconnect, he seems to run against walls etc. But thats the way to make communication in multiplayer games fast enough for internet.

    Greetings,
    Dirk
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

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
  •