zOrder / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

Message reading error #155

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Connect client and server
2.Send client response
3.Client reads response

I was trying to get the client to output the message on the command line, but i 
got index was out of bounds of array error. I am using version r343 or r342

Original issue reported on code.google.com by jethro0...@gmail.com on 18 Oct 2013 at 2:33

GoogleCodeExporter commented 9 years ago
The error is shown in NetBitWriter line 45

Original comment by jethro0...@gmail.com on 18 Oct 2013 at 2:36

GoogleCodeExporter commented 9 years ago
Most likely unmatched read/writes

Original comment by lidg...@gmail.com on 13 Jan 2014 at 8:35

GoogleCodeExporter commented 9 years ago
This question is a bit old, but I made my way to here from Google. So, like me, 
some ppl may find it while looking a solution to this same issue. 

Well, I just figured out what was wrong on my code:

I was using a message.ReadString() twice, while the client had used 
message.Write(string) only once. Remember that everytime you do the 
Write(Value) operation, a new index will be added to the array buffer, so if 
you do ReadString() twice, the program will look for the first string, then for 
the second string, which will not exist in the array. That's why you get the 
"our of range" exception sometimes.

Also, if you wrote anInt32 (for example), make sure to read an Int32, or the 
read and writes won't match, as someone posted above.

Original comment by fr92...@gmail.com on 19 Jan 2014 at 4:41