user1901231
user1901231

Reputation: 49

C# TCP socket connection, output IP address

I brought the question up a few days back on how to output/parse an IP address. Some suggestions were provided, and after a couple days of hitting my head against the wall, attempting the different suggestions, I'm no further. I'm sure the suggestions were OK, but the method in which I was trying to utilize them is where I failed.

So...I'd like to start from just a basic perspective.

  {
        BaseClient bc = null;
        try
        {
            if (m_TCP_Socket == null)
            {
                Console.Write("Client disconnected");
            }
            else
            {   

                //Console.WriteLine("New TCP connection made.");

                bc = GetNewClient();
                bc.Socket = m_TCP_Socket.EndAccept(ar);
                lock (m_clients)
                    m_clients.Add(bc);

                bc.OnConnect();
                bc.BeginReceive();
            }
}

}

I would like for it to simply console out, "New TCP Connection made. IP:###.###.###.###. If you respond, please don't be to presumptuous about what I may know, and not know, as I am student, and trying to learn things.

Upvotes: 0

Views: 401

Answers (1)

CodeCaster
CodeCaster

Reputation: 151720

It's all in the manual. Socket.EndAccept() returns a Socket, from which you can read the RemoteEndPoint property which will be an IPEndPoint, which has an Address property. I think you're looking for the latter.

Upvotes: 1

Related Questions