Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Strange problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
shadevamp...@gmail.com  
View profile  
 More options Dec 15 2007, 1:13 pm
From: shadevamp...@gmail.com
Date: Sat, 15 Dec 2007 10:13:01 -0800 (PST)
Local: Sat, Dec 15 2007 1:13 pm
Subject: Strange problem
I have a strange problem. I'm currently working on a Pong game, and I
want to add a multiplayer support / feature. First I made the whole
networking with strings (it's an old story, my friend wrote a net lib,
supports only strings, and he told me, to try it...). It worked fine
in most of the cases, but it was too slow, but I used strings only
because the compatibility (with the previous net lib) and I thought if
I change strings to dotNet types it'll work fine. I changed.

But then, it made a lot of strange things. I can connect to the
server, or if I'm the server the client can connect to me, but when I
start to send messages through Sequenced1 most of the cases I get an
error:

System.IndexOutOfRangeException: Index was outside the bounds of the
array.
   at Lidgren.Library.Network.NetBitStreamUtil.ReadBytes(Byte[]
fromBuffer, Int32 numberOfBytes, Int32 readBitOffset, Byte[]
destination, Int32 destinationByteOffset)
   at Lidgren.Library.Network.NetBuffer.ReadBytes(Int32 numberOfBytes)
   at Lidgren.Library.Network.NetBuffer.ReadFloat()
   at Lidgren.Library.Network.NetBuffer.ReadSingle()
   at Lidgren.Library.Network.NetMessage.ReadSingle()
...

And when I get this error, it's always the first "game
message" (contains positions and vectors). In addition to this, the
game works sometimes! And during the game this error newer happens!
I'm totally at a loss...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lidgren  
View profile  
 More options Dec 15 2007, 4:46 pm
From: lidgren <lidg...@gmail.com>
Date: Sat, 15 Dec 2007 13:46:57 -0800 (PST)
Local: Sat, Dec 15 2007 4:46 pm
Subject: Re: Strange problem
It looks like you're trying to read more data from the packet than
you wrote. What Write*() and Read*() methods are you using?

--michael

On 15 Dec, 19:13, shadevamp...@gmail.com wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
shadevamp...@gmail.com  
View profile  
 More options Dec 16 2007, 7:26 am
From: shadevamp...@gmail.com
Date: Sun, 16 Dec 2007 04:26:03 -0800 (PST)
Local: Sun, Dec 16 2007 7:26 am
Subject: Re: Strange problem
First, thank you to the fast replay. Second, the code is:

        public static void CollectToMessage(ref NetMessage ref_msg,
byte in_message_code)
        {
            PongGame.Log.WriteLine("CollecToMessage");
            // player's name
            ref_msg = new NetMessage();
            ref_msg.Write(in_message_code);
            ref_msg.Write((float)NetTime.Now);
            //ref_msg.WriteSignedSingle((Single)NetTime.Now, 32);

            if (GameDatas.PlayerType == ePlayers.One)
            {
                // bet positions (left and back) and velocities (left)
(only x and z coords)
                XnaSerialization.Write(ref_msg, new
Vector4(mp_bet_left_z, mp_bet_back_x, mp_bet_left_velocity.X,
mp_bet_left_velocity.Z));
                // bet velocities (back) and ball pos(x, z)
                XnaSerialization.Write(ref_msg, new
Vector4(mp_bet_back_velocity.X, mp_bet_back_velocity.Z,
mp_ball_position.X, mp_ball_position.Z));
                // ball velocity (x,z) + slave velocity (x, z)
                XnaSerialization.Write(ref_msg, new
Vector4(mp_ball_velocity.X, mp_ball_velocity.Z,
mp_ball_slave_velocity.X, mp_ball_slave_velocity.Z));

                /*_ret +=
string.Format(PongGame.SpecParser.FormatProvider, "{0}|{1}|{2}|{3}|{4}|
{5}",
                    mp_ball_position.X, mp_ball_position.Z,
                    mp_ball_velocity.X, mp_ball_velocity.Z,
                    mp_ball_slave_velocity.X,
mp_ball_slave_velocity.Z);*/
            }
            else
            {
                // bet positions (right(z) and front(x))
                XnaSerialization.Write(ref_msg, new
Vector2(mp_bet_right_z, mp_bet_front_x));
                // bet velocities (right and front) (only x and z
coords)
                XnaSerialization.Write(ref_msg, new
Vector4(mp_bet_right_velocity.X, mp_bet_right_velocity.Z,
mp_bet_front_velocity.X, mp_bet_front_velocity.Z));
            }

            PongGame.Log.WriteLine(string.Format("[Collect] length:
{0}; sequence num: {1}; ref_msg: {2}", ref_msg.Length,
ref_msg.SequenceNumber, ref_msg.ToString()),

nNiceLookingPong_NE.nCore.nDiagnostic.LogMessageType.Information);
        }

        public static void UpdateDatasFromMessage(NetMessage
m_game_datas)
        {
            PongGame.Log.WriteLine(string.Format("[Update] length:
{0}; sequence num: {1}; ref_msg: {2}", m_game_datas.Length,
m_game_datas.SequenceNumber, m_game_datas.ToString()),

nNiceLookingPong_NE.nCore.nDiagnostic.LogMessageType.Information);

            if (GameDatas.PlayerType == ePlayers.One)
            {
                // --- we're the 1st player
                // bet positions (right(z) and front(x))
                Vector2 vec2 =
XnaSerialization.ReadVector2(m_game_datas);
                mp_bet_right_z = vec2.X;
                mp_bet_front_x = vec2.Y;

                // bet velocities (right and front) (only x and z
coords)
                Vector4 vec4 =
XnaSerialization.ReadVector4(m_game_datas);
                mp_bet_right_velocity.X = vec4.X;
                mp_bet_right_velocity.Z = vec4.Y;
                mp_bet_front_velocity.X = vec4.Z;
                mp_bet_front_velocity.Z = vec4.W;
            }
            else
            {
                // --- we're the 2nd player
                Vector4 vec4 =
XnaSerialization.ReadVector4(m_game_datas);
                mp_bet_left_z = vec4.X;
                mp_bet_back_x = vec4.Y;
                mp_bet_left_velocity.X = vec4.Z;
                mp_bet_left_velocity.Z = vec4.W;

                vec4 = XnaSerialization.ReadVector4(m_game_datas);
                mp_bet_back_velocity.X = vec4.X;
                mp_bet_back_velocity.Z = vec4.Y;
                mp_ball_position.X = vec4.Z;
                mp_ball_position.Z = vec4.W;
                mp_ball_position.Y = 0.0f;

                vec4 = XnaSerialization.ReadVector4(m_game_datas);
                mp_ball_velocity.X = vec4.X;
                mp_ball_velocity.Z = vec4.Y;
                mp_ball_velocity.Y = 0.0f;
                mp_ball_slave_velocity.X = vec4.Z;
                mp_ball_slave_velocity.Z = vec4.W;
                mp_ball_slave_velocity.Y = 0.0f;
            }
        }
Comment: I use my system like this: every game-update calls the
network.update -> it gets the messages and if it's not a game-message,
it do it in that update (e.g. a client disconnected message, or a
client connection request message, ...; they come in the
NetChannel.Ordered1) If it's a game-message (NetChannel.Sequenced1),
the network class gets a Single -> it's the time lable. If it's the
last message (biggest time label) it store it in a cache variable (the
whole NetMessage), and in the end of the network.update process the
last (cached) game-message (only the last). And here comes the
UpdateDatasFromMessage call, which get the NetMessage, and then read
the vectors from it and store in a shadred GameDatas class -> then the
game can refresh the game object datas from this shared GameDatas
class.

Anyway, the sending of the game datas is this way: every game.update
calls network.sendGameDatas, but it sends the game datas only if the
timer allow it (now it's 70ms -> about 14 times/sec). When it sends
the datas, it calls the CollectToMessage function, which gets the
datas from the shared GameDatas class (it's updated in every
game.update, because it's used in the collision detection too).

A game-message looks like: 1byte code (every type of the messages have
a non-zero code, game-message's code is: 1), 4 bytes (float) time-
label, and then the datas (it depends on the type of the player, a
server gets less datas and sends more datas, bacause the server watchs
not only the server-player's bets but the ball as well).

I made a logs every time (with client and with server too), and it
writes that the client sends 29 bytes and the server gets 29 bytes,
and that's why I'm totally lost, because the message is correct, and I
don't read more then I wrote.

But the strangest thing is that this is sometimes works! If it never
works i think i made something wrong, I read too much from the message
I sent, but it sometimes fine...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lidgren  
View profile  
 More options Dec 16 2007, 7:35 am
From: lidgren <lidg...@gmail.com>
Date: Sun, 16 Dec 2007 04:35:18 -0800 (PST)
Local: Sun, Dec 16 2007 7:35 am
Subject: Re: Strange problem
The code looks good; but i noticed you're writing/reading different
amount of data depending on
the PlayerType enum - could it be this variable gets out of sync
between coupled read/writes?

Also, I recommend using msg.WriteSendStamp() and msg.ReadSentStamp()
since
NetTime.Now only returns local time, which cannot be compared upon
receiving.

--michael

On 16 Dec, 13:26, shadevamp...@gmail.com wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
shadevamp...@gmail.com  
View profile  
 More options Dec 16 2007, 12:53 pm
From: shadevamp...@gmail.com
Date: Sun, 16 Dec 2007 09:53:47 -0800 (PST)
Local: Sun, Dec 16 2007 12:53 pm
Subject: Re: Strange problem
Yes, it was (tha PlayerType enum). Sometimes (if my pc is the slower,
and I'm the server) the PlayerType is not set to the correct player
type (when the game starts).
Thank you, you helped a lot!

On Dec 16, 1:35 pm, lidgren <lidg...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »