Here is the rumpus.
I am building a networked app using websocket-sharp and I have run into an issue where the server sends hundreds (not consistently the same amount) of duplicate messages to the client, heres the breakdown.
1.) The client connects (This handshake works fine).
2.) Upon client connection the server sends said client the session ID created for that connection. (This works)
3.) The client receives and stores the session ID. (This works and no duplicates are sent here)
4.) The client sends a request to the lobby system on the server to create a match. (This works and is received correctly)
5.) The server receives the match creation requests, creates the match and sends the match data back to the client (One message is actually sent but the client receives hundreds of the same message (all messages are the same size and contain the same info)).
I have reviewed my lobby system logic and there is no loop that could be sending the match creation reply multiple times, furthermore I know that the "Send" method on the server is only being called once.
I have looked through the websocket-sharp documentation, I thought maybe somehow there were hundreds of sessions being made from one connection or some non-sense along those lines but I am connecting one client and only one session exits :/
Let me know if you have any ideas how this could be happening. Thanks in advance.
See below for code.
Server:
Send Method:
public void Send (string path, string targetID, string script, string method, params object[] data) {
print ("SERVER: Sending Message");
WebSocketServiceHost host = null;
GetSocketServer ().WebSocketServices.TryGetServiceHost (path, out host);
if (host != null) {
Network.Packet packet = new Network.Packet ("Server", targetID, script, method, data);
if (targetID != "Broadcast") {
GetSocketServer ().WebSocketServices.Broadcast (Formatter.singleton.Serialize (packet));
} else if (targetID == "Service") {
host.Sessions.Broadcast (Formatter.singleton.Serialize (packet));
} else {
host.Sessions.SendToAsync (Formatter.singleton.Serialize (packet), targetID);
}
}
}
Client:
Receive Methods:
GetPersistent ().OnMessage += MessageHandler;
void MessageHandler (object sender, MessageEventArgs e) {
Debug.Log ("CLIENT: Message Recieved");
Network.singleton.Recieve (e.RawData);
}
Network: (Used by both Server and Client)
Receive Methods:
public void Recieve (byte[] data) {
object obj = Formatter.singleton.Deserialize (data);
messages.Add (messages.Count, obj);
}
IEnumerator ProcessorCoro () {
WaitForSeconds delay = new WaitForSeconds (Time.deltaTime);
while (true) {
if (messages.Count >= 1) {
Process (messages [(messages.Count - 1)]);
messages.Remove ((messages.Count - 1));
}
yield return delay;
}
}
public void Process (object data) {
Network.Packet packet = (Network.Packet)data;
switch (packet.script) {
case "Home":
Home.singleton.SendMessage (packet.method, data, SendMessageOptions.DontRequireReceiver);
break;
case "Arena":
Arena.singleton.SendMessage (packet.method, data, SendMessageOptions.DontRequireReceiver);
break;
case "Client":
Client.singleton.SendMessage (packet.method, data, SendMessageOptions.DontRequireReceiver);
break;
case "Database":
Database.singleton.SendMessage (packet.method, data, SendMessageOptions.DontRequireReceiver);
break;
}
}