/// <summary>
 /// Triggered when a Client attempts to Connect. Accepts the connection and begins waiting for Data
 /// </summary>
 /// <param name="asyn">Associated IAsyncResult object</param>
 private static void OnClientConnect(IAsyncResult asyn)
 {
     ClientStream tempClientStream = new ClientStream(listeningSock.EndAccept(asyn), SocketCounter);
     clientStreamList.Add(tempClientStream);
     WaitForData(tempClientStream);
     Interlocked.Increment(ref SocketCounter);
     Log.AddClientText("Info client has connected.", tempClientStream.Index);
     listeningSock.BeginAccept(new AsyncCallback(OnClientConnect), null);
 }
 /// <summary>
 /// Constructor which starts a SocketPacket based on a Client object.
 /// </summary>
 /// <param name="iServer">Associated Client object</param>
 public SocketPacket(ClientStream iClientStream)
 {
     Socket = iClientStream.Socket;
     ClientIndex = iClientStream.Index;
     ClientStream = iClientStream;
 }
 /// <summary>
 /// An always-active function that waits for the client to send data to the server. Eventually trigers OnDataReceived().
 /// </summary>
 /// <param name="waitClientStream">Associated ClientStream object</param>
 private static void WaitForData(ClientStream waitClientStream)
 {
     if (asyncWorkerCallBack == null) { asyncWorkerCallBack = new AsyncCallback(OnDataReceived); }
     SocketPacket tempSocketPacket = new SocketPacket(waitClientStream);
     waitClientStream.Socket.BeginReceive(
         tempSocketPacket.DataBuffer,
         0,
         tempSocketPacket.DataBuffer.Length,
         SocketFlags.None,
         asyncWorkerCallBack,
         tempSocketPacket
     );
 }