PC Review


Reply
Thread Tools Rate Thread

How do I get an IP address from a socket?

 
 
=?Utf-8?B?TWF0dF9pc19hX25vdmljZQ==?=
Guest
Posts: n/a
 
      29th Dec 2004
I am writing a server to open a TCPListener, the client connects, and the
server returns a Socket. I want to know what IP address is connected to my
server. How do I retrieve the IP address of my client from the Socket?

Thanks.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWF0dF9pc19hX25vdmljZQ==?=
Guest
Posts: n/a
 
      29th Dec 2004
I am answering my own question.

Socket socketForClient =
tcpListener.AcceptSocket( );

if (socketForClient.Connected)
{
Console.WriteLine("{0}", socketForClient.RemoteEndPoint.ToString( ));
Console.WriteLine("Client connected");
}

That will print the IP address and port of the client connected on
socketForClient.

"Matt_is_a_novice" wrote:

> I am writing a server to open a TCPListener, the client connects, and the
> server returns a Socket. I want to know what IP address is connected to my
> server. How do I retrieve the IP address of my client from the Socket?
>
> Thanks.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Only one usage of each socket address (protocol/network address/port)is normally permitted pbd22 Microsoft C# .NET 18 3rd Feb 2008 12:56 AM
Socket.BeginSendTo and Socket.BeginSendFrom on a single Socket instancefrom multiple threads Jonas Hei Microsoft C# .NET 2 22nd Jun 2005 12:10 PM
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" Daniel Microsoft Dot NET 1 15th Mar 2005 11:37 AM
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" Daniel Microsoft Dot NET Framework 3 12th Feb 2005 02:53 PM
Windows Socket error: Only one usage of each socket address ... Ron Reynolds Windows XP Performance 0 9th Aug 2003 03:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:21 PM.