hi!

i use tcpclient to get connections from clients to my server. but i need the information of the ip address of that client. i know that i have to derive a mytcpclient from the tcpclient class, but i get some errors when extracting the socket out of it. the following code was done by me, but it won´t work!

class mytcpclient : tcpclient
        {
        public mytcpclient(TcpClient client)
             {}
        public new Socket Client
             {
              get {return base.Client;}
             }
         }

now the code in the main:

TcpClient client = new TcpClient;
mytcpclient mclient = new MyTcpClient(client);
Socket s = mclient.Client;               <--------- using a method of this

client comes up with an error, that there is no instance to that object or so.

can someone please help me? i really need to use tcpclient and to extract that socket to get the remote ip addy!

thany, gry

try this:
class mytcpclient : TcpClient

instead of

class mytcpclient : tcpclient

(note the difference in capitalization)

thanx for answer, but of course i used TcpClient not tcpclient, the compiler instead would have told me ;)

can you post the exact error you are getting

can you post the exact error you are getting

Hi,

I dont think the problem is with the capitalization and you are using the correct format.

Here you code is a little bit confusing. I can't understand why you are extending the TcpClient class and adding socket object to it.

If your requirement is to get the Client's IP address, U can do in following way.

TcpClient client = new TcpClient(servername or ip , port);
IpEndPoint ipend = client.Client.RemoteEndPoint;
Console.WriteLine(IPAddress.Parse(ipend.Address.ToString());

Thanks,
Kedar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.