473,386 Members | 1,969 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,386 software developers and data experts.

Getting the connected IP from TcpListener.AcceptTcpClient

Is it possible to get the ip address of the pc connecting to my
TcpListener? Here's how my code works so far:
listener = new TcpListener(_myIP, _port);
listener.Start();
// block until we get a connection
TcpClient client = listener.AcceptTcpClient();

// at this point I need to store the IP address for
// future ref... but how!?
Any help would be great - thanks!
Nov 17 '05 #1
1 4526
Benny,

In .NET 1.1 and before, if you get the TcpClient, you didn't have access
to the underlying socket. Because of this, you would have to call the
AcceptSocket method to get a socket, and then get the endpoint from there.

In .NET 2.0, the TcpClient class exposes the Client property, which will
give you access to the underlying Socket.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Is it possible to get the ip address of the pc connecting to my
TcpListener? Here's how my code works so far:
listener = new TcpListener(_myIP, _port);
listener.Start();
// block until we get a connection
TcpClient client = listener.AcceptTcpClient();

// at this point I need to store the IP address for
// future ref... but how!?
Any help would be great - thanks!

Nov 17 '05 #2

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

Similar topics

2
by: MuZZy | last post by:
Hi, The app i develop supose to have a remote control/reporting feature, so that if a client connects to it, he can obtain information about application state and to send some commands. I...
2
by: Coder | last post by:
hi, i have a simple question; Suppose that followig code is a thread; /***************************************************/ listener = new TcpListener( IP, PORT); listener.Start(); ...
1
by: Nuno Magalhaes | last post by:
This code gives me the runtime error "Specified cast is not valid": MyTcpClient ClientTcp=(MyTcpClient)ListenerTcp.AcceptTcpClient(); MyTcpClient is a class that inherits from TcpClient. Why...
3
by: Marty | last post by:
Hi, I have this DLL made with VB.NET made as a Class Library project. I know this is managed code. I have my other made with VC++.NET, unmanaged code. The point is that I want to use...
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. ...
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: Chris Johnson | last post by:
Hey guys, A while back I posted a message about multithreading in .NET 2.0 to maintain GUI responsivness while using a TCPListener to monitor a TCP port for transmission. One of the MVP's in the...
5
by: Jerry Spence1 | last post by:
I have the following example of a tcpListener. I have a device external to my PC which is sending a TCP request on port 10002. This is working OK as I have a network sniffer on my PC and can see...
11
by: batmanfreeze | last post by:
I am using C# in .Net 1.1, and need to access the 'Client' Property of TcpClient, so I created a derived class to do this based upon the Microsoft Sample, located at:...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.