473,386 Members | 1,773 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.

TCPclient and IP adress

Hello,

i made an app that use sockets, based on this sample :

http://www.microsoft.com/downloads/d...displaylang=en

i'have a problem, i can't obtain the client IP adress on the server side (i
have a pointer to a TCPclient object)

Is averyone that know how to retrieve the IPadress from a TCPclient Object ?

Thanks for your help

Sebho
Nov 20 '05 #1
4 3033
I am not familiar with that sample but I have a client-server app that I
have developed and to get the clients IP address in the server app I
accept the incoming connection and then use:

IPAddress.Parse(CType(oSocket.RemoteEndPoint,IPEnd Point).Address.ToString())

maybe this will help?

Shawn shelton

Sebho wrote:
Hello,

i made an app that use sockets, based on this sample :

http://www.microsoft.com/downloads/d...displaylang=en

i'have a problem, i can't obtain the client IP adress on the server side (i
have a pointer to a TCPclient object)

Is averyone that know how to retrieve the IPadress from a TCPclient Object ?

Thanks for your help

Sebho


Nov 20 '05 #2
On 2003-11-05, Sebho <no**********@ifrance.com> wrote:
Hello,

i made an app that use sockets, based on this sample :

http://www.microsoft.com/downloads/d...displaylang=en

i'have a problem, i can't obtain the client IP adress on the server side (i
have a pointer to a TCPclient object)

Is averyone that know how to retrieve the IPadress from a TCPclient Object ?

Thanks for your help

Sebho


Unfortunately, the TcpClient class does not directly expose a method to
do this. The only way it can be done, is to create your own class that
inherits from TcpClient - that way you can access the protected Client
property. It would look something like:

Public Class MyTcpClient
Inherits TcpClient

' Add your contructors
....

' Add your client Ip property
Public ReadOnly Property ClientIP() As IPAddress
Get
Return CType(Me.Client.RemoteEndPoint, IPEndPoint).Address
End Get
End Property

End Class

Anyway, it's a little bit of air code :)

HTH
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #3
Sorry i'm a newbie ......
ok for the subclass, but i have a TCPlistener object, and the accept method
will return a TCPclient object, how can i do for the TCPlistener.accept
return a MyTcpClient object ?

thanks for your help

Sebho

"Tom Shelton" <to*@mtogden.com> a écrit dans le message de
news:e$**************@TK2MSFTNGP09.phx.gbl...
On 2003-11-05, Sebho <no**********@ifrance.com> wrote:
Hello,

i made an app that use sockets, based on this sample :

http://www.microsoft.com/downloads/d...displaylang=en
i'have a problem, i can't obtain the client IP adress on the server side (i have a pointer to a TCPclient object)

Is averyone that know how to retrieve the IPadress from a TCPclient Object ?
Thanks for your help

Sebho


Unfortunately, the TcpClient class does not directly expose a method to
do this. The only way it can be done, is to create your own class that
inherits from TcpClient - that way you can access the protected Client
property. It would look something like:

Public Class MyTcpClient
Inherits TcpClient

' Add your contructors
....

' Add your client Ip property
Public ReadOnly Property ClientIP() As IPAddress
Get
Return CType(Me.Client.RemoteEndPoint, IPEndPoint).Address
End Get
End Property

End Class

Anyway, it's a little bit of air code :)

HTH
--
Tom Shelton
MVP [Visual Basic]

Nov 20 '05 #4
In article <eI**************@tk2msftngp13.phx.gbl>, Sebho wrote:
Sorry i'm a newbie ......
ok for the subclass, but i have a TCPlistener object, and the accept method
will return a TCPclient object, how can i do for the TCPlistener.accept
return a MyTcpClient object ?

thanks for your help

Sebho


Well with out inheriting from the TCPListener class and overriding the
AcceptTcpClient method... I would instead use the AcceptSocket method
and then add a constructor to your TcpClient class that takes a Socket
as a parameter...

Public Class MyTcpClient
Public Sub New(ByVal Client As Socket)
Me.Client = Client
End Sub

....

End Class

Then,
Dim s As Socket
Dim c As MyTcpClient

....
s = myListener.AcceptSocket()
c = new MyTcpClient(s)
...

HTH
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5

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

Similar topics

3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
2
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the...
3
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
0
by: Torsten Brasch | last post by:
Hi All and Happy New Year ;) I have a very strange problem with System.Net.Sockets.TcpClient(). For some reason, the number of bytes I can receive is limited to 5460 bytes. I made sure that the...
1
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client...
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
4
by: Peter | last post by:
Hi I rewrite an old C Programm to C# (Framework 1.1) - it is an easy FTP- Client. I create a "Command-Channel" using TcpClient, a "Command-Reader" and a "Command-Writer" to speak with the FTP...
5
by: puzzlecracker | last post by:
It looks like i need to get IPEndPoint first, but I cannot figure out from msdn the eventual obtainment of machine name and port number. Please suggest a solution. Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.