Socket communication problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sa¹o Zagoranski

    #1

    Socket communication problem

    Hi!



    I'm writing a simple 3D First person shooter game. It is a multiplayer
    game, where all the players connect

    to one server.



    I'm using the System.Net.Sock ets.Socket class for communication over TCP
    protocol (I know that good games

    use UDP).

    I report changes to the server through simple Messages (a messages would
    look like: [messOwner, Type, ...]),

    where a typical message is about 20-30 bytes in size.



    So if a client moves I send a message ([client1, Move, NewPosition]) to
    the server and the server then transmits

    this message to the other clients in the game.

    The messages is sent using the Socket.Send(byt e[]) method.



    A typical server loop looks like this:

    while (true)

    {

    socket.Receive( buffer);

    Message m = DecodeMessage(b uffer); // I just create a message
    object from the buffer here

    MyMessageQueue. Enqueue(m); // the message is enqueued in a simple
    message queue and is processed on another thread

    }



    The problem is this:

    If a client is constantly moving, it is sending a Move message each
    frame (about 40-60 messages on average)

    and the server doesn't GET all of them! Even if there is only one player
    - over a LAN network only 30% of all messages arrives (if the server and
    the client

    are on the same machine all the messages get there). I know this because
    I've added counters on both sides .



    The message queue works very well... what ever get's in there - gets
    processed. Could the problem be in the Receive method?

    Is it possible that, while I'm processing the message, the client sends
    more than one message in that time (overwrites what was there before)
    and the server just

    picks up the last data received?



    If so... anyway to get around that? (While still sending information
    every frame if neccessary - I will changes this only as a last resort :(
    ).



    thanks,

    saso






  • Sagaert Johan

    #2
    Re: Socket communication problem

    Check the result of the sent method to see if all bytes are sent.
    perhaps you are overflowing the tcpip buffer


    "Sa¹o Zagoranski" <saso.zagoransk i@guest.arnes.s i> wrote in message news:d6pkpk$emb $1@planja.arnes .si...
    Hi!



    I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect

    to one server.



    I'm using the System.Net.Sock ets.Socket class for communication over TCP protocol (I know that good games

    use UDP).

    I report changes to the server through simple Messages (a messages would look like: [messOwner, Type, ...]),

    where a typical message is about 20-30 bytes in size.



    So if a client moves I send a message ([client1, Move, NewPosition]) to the server and the server then transmits

    this message to the other clients in the game.

    The messages is sent using the Socket.Send(byt e[]) method.



    A typical server loop looks like this:

    while (true)

    {

    socket.Receive( buffer);

    Message m = DecodeMessage(b uffer); // I just create a message object from the buffer here

    MyMessageQueue. Enqueue(m); // the message is enqueued in a simple message queue and is processed on another thread

    }



    The problem is this:

    If a client is constantly moving, it is sending a Move message each frame (about 40-60 messages on average)

    and the server doesn't GET all of them! Even if there is only one player - over a LAN network only 30% of all messages arrives (if the server and the client

    are on the same machine all the messages get there). I know this because I've added counters on both sides .



    The message queue works very well... what ever get's in there - gets processed. Could the problem be in the Receive method?

    Is it possible that, while I'm processing the message, the client sends more than one message in that time (overwrites what was there before) and the server just

    picks up the last data received?



    If so... anyway to get around that? (While still sending information every frame if neccessary - I will changes this only as a last resort :( ).



    thanks,

    saso





    Comment

    • Saso Zagoranski

      #3
      Re: Socket communication problem

      I have checked it...



      the number of bytes send by socket.send(... ) are the same as the amount
      that should have been send...



      about 10kB in a minute but the server receives only 30% of the data.



      What do you think about this possibility?



      I wrote this in the first post:

      Is it possible that, while I'm processing the message, the client sends
      more than one message in that time (overwrites what was there before)
      and the server just

      picks up the last data received?



      saso



      _____

      Od: Sagaert Johan [mailto:REMOVEsa gaert_j@hotmail .com]
      Poslano: 22. maj 2005 20:24
      Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
      Pogovor: Socket communication problem
      Zadeva: Re: Socket communication problem


      Check the result of the sent method to see if all bytes are sent.

      perhaps you are overflowing the tcpip buffer





      "Sa¹o Zagoranski" <saso.zagoransk i@guest.arnes.s i> wrote in message
      news:d6pkpk$emb $1@planja.arnes .si...

      Hi!



      I'm writing a simple 3D First person shooter game. It is a multiplayer
      game, where all the players connect

      to one server.



      I'm using the System.Net.Sock ets.Socket class for communication over TCP
      protocol (I know that good games

      use UDP).

      I report changes to the server through simple Messages (a messages would
      look like: [messOwner, Type, ...]),

      where a typical message is about 20-30 bytes in size.



      So if a client moves I send a message ([client1, Move, NewPosition]) to
      the server and the server then transmits

      this message to the other clients in the game.

      The messages is sent using the Socket.Send(byt e[]) method.



      A typical server loop looks like this:

      while (true)

      {

      socket.Receive( buffer);

      Message m = DecodeMessage(b uffer); // I just create a message
      object from the buffer here

      MyMessageQueue. Enqueue(m); // the message is enqueued in a simple
      message queue and is processed on another thread

      }



      The problem is this:

      If a client is constantly moving, it is sending a Move message each
      frame (about 40-60 messages on average)

      and the server doesn't GET all of them! Even if there is only one player
      - over a LAN network only 30% of all messages arrives (if the server and
      the client

      are on the same machine all the messages get there). I know this because
      I've added counters on both sides .



      The message queue works very well... what ever get's in there - gets
      processed. Could the problem be in the Receive method?

      Is it possible that, while I'm processing the message, the client sends
      more than one message in that time (overwrites what was there before)
      and the server just

      picks up the last data received?



      If so... anyway to get around that? (While still sending information
      every frame if neccessary - I will changes this only as a last resort :(
      ).



      thanks,

      saso






      Comment

      • Saso Zagoranski

        #4
        Re: Socket communication problem



        I have found the problem (not the solution :( )



        One Move sends 24 bytes over the network. If the player moves very
        slowly everything is ok...

        but if you move very fast the Receive method receives MORE than 24 bytes
        (up to 200!)...



        how to get around that?



        _____

        Od: Saso Zagoranski [mailto:saso.zag oranski@guest.a rnes.si]
        Poslano: 22. maj 2005 22:47
        Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
        Pogovor: Socket communication problem
        Zadeva: Re: Socket communication problem


        I have checked it...



        the number of bytes send by socket.send(... ) are the same as the amount
        that should have been send...



        about 10kB in a minute but the server receives only 30% of the data.



        What do you think about this possibility?



        I wrote this in the first post:

        Is it possible that, while I'm processing the message, the client sends
        more than one message in that time (overwrites what was there before)
        and the server just

        picks up the last data received?



        saso



        _____

        Od: Sagaert Johan [mailto:REMOVEsa gaert_j@hotmail .com]
        Poslano: 22. maj 2005 20:24
        Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
        Pogovor: Socket communication problem
        Zadeva: Re: Socket communication problem


        Check the result of the sent method to see if all bytes are sent.

        perhaps you are overflowing the tcpip buffer





        "Sa¹o Zagoranski" <saso.zagoransk i@guest.arnes.s i> wrote in message
        news:d6pkpk$emb $1@planja.arnes .si...

        Hi!



        I'm writing a simple 3D First person shooter game. It is a multiplayer
        game, where all the players connect

        to one server.



        I'm using the System.Net.Sock ets.Socket class for communication over TCP
        protocol (I know that good games

        use UDP).

        I report changes to the server through simple Messages (a messages would
        look like: [messOwner, Type, ...]),

        where a typical message is about 20-30 bytes in size.



        So if a client moves I send a message ([client1, Move, NewPosition]) to
        the server and the server then transmits

        this message to the other clients in the game.

        The messages is sent using the Socket.Send(byt e[]) method.



        A typical server loop looks like this:

        while (true)

        {

        socket.Receive( buffer);

        Message m = DecodeMessage(b uffer); // I just create a message
        object from the buffer here

        MyMessageQueue. Enqueue(m); // the message is enqueued in a simple
        message queue and is processed on another thread

        }



        The problem is this:

        If a client is constantly moving, it is sending a Move message each
        frame (about 40-60 messages on average)

        and the server doesn't GET all of them! Even if there is only one player
        - over a LAN network only 30% of all messages arrives (if the server and
        the client

        are on the same machine all the messages get there). I know this because
        I've added counters on both sides .



        The message queue works very well... what ever get's in there - gets
        processed. Could the problem be in the Receive method?

        Is it possible that, while I'm processing the message, the client sends
        more than one message in that time (overwrites what was there before)
        and the server just

        picks up the last data received?



        If so... anyway to get around that? (While still sending information
        every frame if neccessary - I will changes this only as a last resort :(
        ).



        thanks,

        saso






        Comment

        • Saso Zagoranski

          #5
          Re: Socket communication problem



          I solved it... If I receive a lot of data in one package I just split it
          in more messages.



          However... since there are so many messages going over the network,
          everything

          still works slowly... :(



          _____

          Od: Saso Zagoranski [mailto:saso.zag oranski@guest.a rnes.si]
          Poslano: 22. maj 2005 23:21
          Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
          Pogovor: Socket communication problem
          Zadeva: Re: Socket communication problem




          I have found the problem (not the solution :( )



          One Move sends 24 bytes over the network. If the player moves very
          slowly everything is ok...

          but if you move very fast the Receive method receives MORE than 24 bytes
          (up to 200!)...



          how to get around that?



          _____

          Od: Saso Zagoranski [mailto:saso.zag oranski@guest.a rnes.si]
          Poslano: 22. maj 2005 22:47
          Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
          Pogovor: Socket communication problem
          Zadeva: Re: Socket communication problem


          I have checked it...



          the number of bytes send by socket.send(... ) are the same as the amount
          that should have been send...



          about 10kB in a minute but the server receives only 30% of the data.



          What do you think about this possibility?



          I wrote this in the first post:

          Is it possible that, while I'm processing the message, the client sends
          more than one message in that time (overwrites what was there before)
          and the server just

          picks up the last data received?



          saso



          _____

          Od: Sagaert Johan [mailto:REMOVEsa gaert_j@hotmail .com]
          Poslano: 22. maj 2005 20:24
          Objavljeno v: microsoft.publi c.dotnet.langua ges.csharp
          Pogovor: Socket communication problem
          Zadeva: Re: Socket communication problem


          Check the result of the sent method to see if all bytes are sent.

          perhaps you are overflowing the tcpip buffer





          "Sa¹o Zagoranski" <saso.zagoransk i@guest.arnes.s i> wrote in message
          news:d6pkpk$emb $1@planja.arnes .si...

          Hi!



          I'm writing a simple 3D First person shooter game. It is a multiplayer
          game, where all the players connect

          to one server.



          I'm using the System.Net.Sock ets.Socket class for communication over TCP
          protocol (I know that good games

          use UDP).

          I report changes to the server through simple Messages (a messages would
          look like: [messOwner, Type, ...]),

          where a typical message is about 20-30 bytes in size.



          So if a client moves I send a message ([client1, Move, NewPosition]) to
          the server and the server then transmits

          this message to the other clients in the game.

          The messages is sent using the Socket.Send(byt e[]) method.



          A typical server loop looks like this:

          while (true)

          {

          socket.Receive( buffer);

          Message m = DecodeMessage(b uffer); // I just create a message
          object from the buffer here

          MyMessageQueue. Enqueue(m); // the message is enqueued in a simple
          message queue and is processed on another thread

          }



          The problem is this:

          If a client is constantly moving, it is sending a Move message each
          frame (about 40-60 messages on average)

          and the server doesn't GET all of them! Even if there is only one player
          - over a LAN network only 30% of all messages arrives (if the server and
          the client

          are on the same machine all the messages get there). I know this because
          I've added counters on both sides .



          The message queue works very well... what ever get's in there - gets
          processed. Could the problem be in the Receive method?

          Is it possible that, while I'm processing the message, the client sends
          more than one message in that time (overwrites what was there before)
          and the server just

          picks up the last data received?



          If so... anyway to get around that? (While still sending information
          every frame if neccessary - I will changes this only as a last resort :(
          ).



          thanks,

          saso






          Comment

          Working...