private static void receieveCallback(IAsyncResult ar) { try { TcpStateObject state = (TcpStateObject)ar.AsyncState; Socket s = state.workerSock; int bytesRead = s.EndReceive(ar); if (bytesRead > 0) { state.sb.Append(Encoding.ASCII.GetString(state.socketBuffer, 0, bytesRead)); s.BeginReceive(state.socketBuffer, 0, TcpStateObject.maxBytes, 0, new AsyncCallback(receieveCallback), state); } else { if (state.sb.Length > 1) { socketResponse = state.sb.ToString(); } receiveComplete.Set(); } } catch { } }
private static void recieve(Socket s) { try { TcpStateObject state = new TcpStateObject(); state.workerSock = s; s.BeginReceive(state.socketBuffer, 0, state.socketBuffer.Length, 0, new AsyncCallback(receieveCallback), state); } catch { //Debug.msgbox.show(e.ToString()); } }