Or Nakash

Or Nakash

  • NA
  • 10
  • 5.6k

TCP Sockets

Aug 16 2010 5:20 PM
Hello there guys.
I made a client application in C#. Now, I have a problem when I get the data.
I want to check if it equals to something, but when I do that, I get nothing.
Here's the OnDataRecieved code;

            try
            {
                SocketPacket theSockId = (SocketPacket)asyn.AsyncState;
                int iRx = theSockId.thisSocket.EndReceive(asyn);
                char[] chars = new char[iRx + 1];
                System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
                System.String szData = new System.String(chars);
                richTextBox1.AppendText(szData);

                if(szData=="test")
                {
                              Console.Beep();
                 }
                WaitForData();
                //msg(szData);
            }
            catch (ObjectDisposedException)
            {
                System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
               // MessageBox.Show("Problem in OnDataRecieved");
            }
            catch (SocketException)
            {
                //MessageBox.Show(se.Message);
                msg("Connection dropped.");
            }

Thanks in advance.