473,656 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Acc eptTcpConnectio ns. 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 3202
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.Acc eptTcpConnectio ns. 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.Acc eptSocket 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.Reflecti on;

static Socket GetUnderlyingSo cket(TcpClient c) {
return (Socket) c.GetType.Invok eMember(
"Client",
BindingFlags.In stance | BindingFlags.Ge tProperty |
BindingFlags.No nPublic,
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
1819
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
2707
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 (true) {
2
5596
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 what I've got (and found through all of my research as the necessary code): Type remoteType = Type.GetTypeFromProgID(r2wprogid, r2wserver) ; object remoteObject = Activator.CreateInstance(remoteType, true) ; The call to the...
0
1384
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. ======================================================================== Private Sub DoListen() m_oListener.Start() While True
2
1256
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 computer. Private Function GetRemoteDrives(ByVal RemoteServer As String) As String Dim moMOS As System.Management.ManagementObjectSearcher Dim moObject As System.Management.ManagementObject
3
2502
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 object to be able to invoke a method on my server object and given that the object is built in a C# Class DLL shared between the client and server I'm not sure how to get access to the server object from the remoted object. So, what techniques...
0
1475
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 (Type.InvokeMethod) is used to dynamically invoke a "command-object" in a list. The list of objects are created when server is started (in UI-thread). Each entry in the command list stores a Type reference, an object reference and the method name.
3
7061
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 program works fine on Windows Server 2003 while trying to use WMI to get resource from the itsself computer, just has the problem while remoting to other computer. I did put the permission of all security to "Everyone" on "Windows Managment and...
5
2260
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
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8498
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.