473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Getting remote ip from TcpClient object

Hi,

In quite a fix here. Hope someone can help ASAP. I need
to get the IP address of the client that connects when I
use TcpListener.AcceptTcpConnections. I know I can get
the information using the socket class but I really need
to know how to get this information using the TcpClient
class. I tried writing a class from TcpCLient but then
found out that I can not cast down the inheritance
hierarchy, only up. Any help is greatly
appreciated !!!!! Thanks in advance!!!

Regards,

Ethan
Nov 16 '05 #1
1 3186
Hi Ethan,
In quite a fix here. Hope someone can help ASAP. I need
to get the IP address of the client that connects when I
use TcpListener.AcceptTcpConnections. I know I can get
the information using the socket class but I really need
to know how to get this information using the TcpClient
class. I tried writing a class from TcpCLient but then
found out that I can not cast down the inheritance
hierarchy, only up. Any help is greatly
appreciated !!!!! Thanks in advance!!!


You have to use TcpListener.AcceptSocket to be able to
obtain the peer's address. It isn't that hard to deal
with the Socket class.

--
If you promise, that you will use the Socket class in future,
here is an untested hotfix using reflection on non public
members, which is a no-no-no!!!!! Don't do that at home!

using System.Reflection;

static Socket GetUnderlyingSocket(TcpClient c) {
return (Socket) c.GetType.InvokeMember(
"Client",
BindingFlags.Instance | BindingFlags.GetProperty |
BindingFlags.NonPublic,
null,
c,
null
);
}
--

bye
Rob
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: alex | last post by:
Hi all, I'd like to find the equivalent of the getimagesize() function for remote swf files. Do you how to do this ? thanks in advance, -- alex
1
by: MuZZy | last post by:
HI, How do i get a remote TcpClient address here? // ======================================= TcpListener l = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080); TcpListener.Start(); While...
2
by: Bryan Tubbs | last post by:
I'm having trouble connecting to a remote COM object using Reflection. I've got a Web Form using C# that needs to connect to a COM object on a remote server. The snippet of code that follows is...
0
by: Mark | last post by:
Ok, Why is this so hard too do? I have a TCPListener that's working exactly as expected. It fires off a new thread to listen on calling this function. ...
2
by: Daniel | last post by:
Any ideas why the below function does not work? It just returns the drives of the local computer not the remote one. I don't think it is permissions because I am in the Admins group on the remote...
3
by: Grant Schenck | last post by:
Hello, I have a Windows Service developed in C# .NET. I'm making it a remote server and I can, via an IPC Channel, expose methods and call them from a client. However, I now want my remoted...
0
by: Jan | last post by:
I just started using .NET Remoting. I have a test system (client) which connects to our device (server) running XP Embedded. When my server object is called it uses a library where reflection...
3
by: LamSoft | last post by:
I have the access denied on my ASP.NET C# program while deploy my project from my PC (WinXP) to Server 2003 The program works fine on my PC but get access denied on Server 2003. However the...
5
by: shuvo2k6 | last post by:
Hi, I am working on Remote Data Object (RDO) & MySQL in VB6. I cann't add record in my table. If anybody have Solution, Plz send me. Regards, shuvo2k6
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.