Update: Two Client Problem II

Further development in the two client problem. Today when attempting to recreate the extreme failure of player B I was met with different problems but not the exploding. I tinkered with many pieces of code but still do not know what I changed that fixed the freezing all I really recall doing was adding several Debug.Log calls to see exactly when the program was failing. After getting the second train to not explode I was able to learn that there were several other things wrong with both the server and client side of my programs.

On the client side I have the strange error that although Player B finishes the SpawnTrain() function which spawns in the Player A train, the actual train entity does not appear for several seconds and appears in the wrong location. I have no idea why the train waits to spawn even though the function completes. However, I do suspect that the issue of where the train is spawned is due to the funky math I do to spawn it. When Player B joins the game they notify the server. The server then sends all the available track data and asks player A where their train is. Player A then sends its location relative to the location of its current target waypoint along with the target waypoint index, section its in, and speed its traveling at. The relative location is found by taking the difference between the trains xy and the targets xy. Knowing this I assumed I could simply reverse the calculation, take the targets xy and add the difference xy and you get the trains location. In theory it should work but I believe I am mistaken in some assumption along the way. Another issue is that none of the messages that should be sent from one client to another seem to be getting there (except for the location request).

On the server while inspecting the missing messages issue I found that for some reason messages were being received and then sent to clients seemingly randomly. Sometimes messages were sent from A to A and B, sometimes from A to B or A to A, and sometimes from client A to no one. This bug was easy to track down and fix. To send my messages I use a function called SendToAllExcept which took an IpEndPoint object (a prewritten class from the .net.sockets library which represents IP Address Port pairs) and a message. The function would loop through all the clients connected to the server and if they were not the endpoint provided to the function the message would be sent to them. When analizing this function for issues I realized that it was overly complex. I did not need to exclude based on an endpoint because when receiving any message the server checks if it came from an existing client or not and stores which client sent it if they exist. This means that all I needed to compare in that function is the index of the client not the addresses. This is the better way to do it but when implementing this way I realized why the original implementation did not work. I was using: if (endpoint_a.Equals(endpoint_b)) instead of if( IpEndPoint.Equals(endpoint_a, endpoint_b). I believe the subtle difference meant that instead of using the .Equals to compare IpEndPoints I was using a .Equals which compared objects. After changing to the index send I was able to send the right messages to the right places but the messages still do not seem to be received or handled appropriately by the clients.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php