or nakash

or nakash

  • NA
  • 23
  • 0

Asynchronous Sockets - How to get a IP Address of a client and how to block it when needed.

Feb 18 2010 2:54 PM
Hi.
How to get a IP Address of a client? I am currently using this:
        public void OnClientConnect(IAsyncResult asyn)
        {
            try
            {
                m_socWorker = m_socListener.EndAccept(asyn);
                WaitForData(m_socWorker);
                m_socListener.BeginAccept(new AsyncCallback(OnClientConnect), null);
                AppendText("[" + m_socWorker.RemoteEndPoint.ToString()+ "] Connected.");
            }
            catch (ObjectDisposedException)
            {
                System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }

        }
This code prints the port too and I want it to print only the client's IP Address.

And how to block a IP Address from connecting the server?


Answers (1)