I am trying to create a client/server application which communicates through Sockets. But when I receive data it randomly messed up and does not always (sometimes) show the correct data. The code I use to receive data:
private static void ReceiveCallback(IAsyncResult AR) { try { Socket socket = (Socket)AR.AsyncState; if (SocketConnected(socket)) { int received = socket.EndReceive(AR); byte[] dataBuf = new byte[received]; Array.Copy(_buffer, dataBuf, received); string text = Encoding.ASCII.GetString(dataBuf); if (!text.Contains("GET") && !text.Contains("HTTP") && text != null) { Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt") + ":" + text); } socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket); } } catch { } } can someone explain me why this happends? Thanks in advance!
Also, I have tried to check untill it finds a character (which is on the end of every response '-' but that did not work). Unfortunatley this was the result: 