1
Answer

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

or nakash

or nakash

14y
3.9k
1
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)