or nakash

or nakash

  • NA
  • 23
  • 0

Help with Asynchronous Sockets [OnDataReceived]

Feb 19 2010 3:42 PM
Hey.
I am new with the Asynchronous sockets and I am trying to make a little program.
I want when the client sends the string "doitall", the server does something, I succeeded to do that with the client but I faild with the server. This is the code:

        public void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
                int byteCount = 0;
                byteCount = theSockId.thisSocket.EndReceive(asyn);
                char[] chars = new char[byteCount + 1];
                Encoding.UTF8.GetDecoder().GetChars(theSockId.dataBuffer, 0, byteCount, chars, 0);
                string str = new string(chars);
                AppendText(str);
                if (str == "doitall")
                {
                    MessageBox.Show("works.");
                }
                WaitForData(m_socWorker);
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }

Whats the problem?
And how to send data to a specific IP address?

Answers (3)