title: websocket-sharp server sending duplicate messages
body: <p>Here is the rumpus.</p>
  
  <p>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.</p>
  
  <p>1.) The client connects (This handshake works fine).</p>
  
  <p>2.) Upon client connection the server sends said client the session ID created for that connection. (This works)</p>
  
  <p>3.) The client receives and stores the session ID. (This works and no duplicates are sent here) </p>
  
  <p>4.) The client sends a request to the lobby system on the server to create a match. (This works and is received correctly)</p>
  
  <p>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)).</p>
  
  <p>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.</p>
  
  <p>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 :/</p>
  
  <p>Let me know if you have any ideas how this could be happening. Thanks in advance.</p>
  
  <p>See below for code.</p>
  
  <p><strong>Server:</strong></p>
  
  <p>Send Method:</p>
  
  <pre><code>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);
          }
      }
  }
  </code></pre>
  
  <p><strong>Client:</strong></p>
  
  <p>Receive Methods:</p>
  
  <pre><code>GetPersistent ().OnMessage += MessageHandler;
  
  void MessageHandler (object sender, MessageEventArgs e) {
      Debug.Log ("CLIENT: Message Recieved");
      Network.singleton.Recieve (e.RawData);
  }
  </code></pre>
  
  <p><strong>Network:</strong> (Used by both Server and Client)</p>
  
  <p>Receive Methods: </p>
  
  <pre><code>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 &gt;= 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;
      }
  }
  </code></pre>