public void WaitForData()
 {
     try
     {
         if (m_pfnCallBack == null)
         {
             m_pfnCallBack = new AsyncCallback(OnDataReceived);
         }
         SocketPacket theSocPkt = new SocketPacket();
         theSocPkt.m_currentSocket = m_clientSocket;
         // Start listening to the data asynchronously
         m_result = m_clientSocket.BeginReceive(theSocPkt.dataBuffer,
                                                 0, theSocPkt.dataBuffer.Length,
                                                 SocketFlags.None,
                                                 m_pfnCallBack,
                                                 theSocPkt);
     }
     catch (SocketException se)
     {
         if (se.SocketErrorCode == SocketError.ConnectionReset)
         {
             SetText("Server closed!\n");
             SetTextLblStatus("Server closed!");
             m_clientSocket.Close();
             UpdateControls(false);
         }
     }
     catch (Exception ex)
     {
         SetText("WaitForData: Socket has been closed. Socket error: " + ex.Message.ToString());
         CloseSocket();
         UpdateControls(false);
     }
 }
 // Start waiting for data from the client
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             // Specify the call back function which is to be
             // invoked when there is any write activity by the
             // connected client
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         SocketPacket theSocPkt = new SocketPacket();
         theSocPkt.m_currentSocket = soc;
         // Start receiving any data written by the connected client
         // asynchronously
         soc.BeginReceive(theSocPkt.dataBuffer, 0,
                            theSocPkt.dataBuffer.Length,
                            SocketFlags.None,
                            pfnWorkerCallBack,
                            theSocPkt);
     }
     catch (SocketException se)
     {
         SetText(se.Message);
         --m_clientCount;
     }
 }