public void ReceiveTrackUpdates(Socket socket) { try { RecieveStateObject state = new RecieveStateObject(); state.workSocket = socket; socket.BeginReceive(state.buffer, 0, RecieveStateObject.BufferSize, 0, new AsyncCallback(ReceiveTrackUpdate), state); } catch (Exception e) { CloseSocket(socket); Console.WriteLine(e.ToString()); } }
private void ReceiveTrackUpdate(IAsyncResult ar) { try { RecieveStateObject state = (RecieveStateObject)ar.AsyncState; Socket client = state.workSocket; int bytesRead = client.EndReceive(ar); if (bytesRead > 0) { string value = Encoding.ASCII.GetString(state.buffer, 0, bytesRead); state.sb.Append(value); Console.WriteLine(value); } client.BeginReceive(state.buffer, 0, RecieveStateObject.BufferSize, 0, new AsyncCallback(ReceiveTrackUpdate), state); } catch (Exception e) { CloseSocket((Socket)ar.AsyncState); Console.WriteLine(e.ToString()); } }