// Start the first asynchronous read on the socket socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReadCallback), state); // Callback function called when the read operation completes void ReadCallback(IAsyncResult ar) { // Retrieve the state object and the socket from the asynchronous state object. StateObject state = (StateObject) ar.AsyncState; Socket socket = state.workSocket; // Read data from the socket int bytesRead = socket.EndReceive(ar); // If more data is available, start another read operation if (bytesRead > 0) { state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); socket.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, new AsyncCallback(ReadCallback), state); } // Check for overlapped operations and complete synchronously if necessary if (ar.CompletedSynchronously) { CheckAsyncCallOverlappedResult(ar); } }The System.Net.Sockets namespace is part of the .NET Framework Class Library.