Nightmare with socket object

J

John Tear

Hi

I am currently trying to get the remote IP address of a client
connection using VB.Net:

This is in my class

Private mobjSocket As Socket

' initialize with a raw socket
Public Sub New(ByVal s As Socket)
mobjSocket = s
RaiseEvent Connected(Me)
mobjSocket.BeginReceive(marData, 0, 1024, SocketFlags.None,
AddressOf DoReceive, Nothing)
End Sub

Public ReadOnly Property RemoteIPAddress() As String
Get
Dim objEPRemote As IPEndPoint
objEPRemote = CType(mobjSocket.RemoteEndPoint, IPEndPoint)

RemoteIPAddress = objEPRemote.Address.ToString()
End Get
End Property


When I try to access through a form procedure:

MessageBox.show(sender.RemoteIPAddress())

It doesnt work!!! There is other stuff in their (MSDN multi-user
server example)...

What am I doing which is so WRONG! I only want the remote IP address.

Thanks in advance, (e-mail address removed)
 
R

Richard

MessageBox.show(sender.RemoteIPAddress())
It doesnt work!!! There is other stuff in their (MSDN multi-user
server example)...

What am I doing which is so WRONG! I only want the remote IP address.

Your thread subject sounds like the title to a .NET Slasher movie.
;)

When you say it doesn't work what do you mean? If its just a basic
formatting
error does this help?

RemoteIPAddress = IPAddress.Parse(CType(s.RemoteEndPoint,
IPEndPoint).Address.ToString()))

hth
Richard

p.s
Look out!! Behind you!! Aarrgghhh!!
 
J

John Tear

Hi

Thanks for your reply.

Yeah Im thinking of making a movie called A nightmare on dot net
street! Maybe get Bill Gates to be the first victim!!!

Basically, I have programmed multi-user server apps before using the
dreaded VB6 winsock controls. Im fairly new to OOP (I used C++ many
years ago but found myself using VB6 because I was lazy!!!)

All I would like to do is get the IP address of clients conencted to
the server. I have a Client class that contains a socket instance
called mobjSocket. I can get clients to connect, send and receive data
ok but I cannot get the remote IP address.

When I say it doesnt work, it just doesnt work. When I add the
MessageBox.Show to try and grab the IP address the clients cannot even
connect! NO ERROR MESSAGES!!! YES Bill Gates will be the first victim.
hahaha!

I will try your suggestion when I get home later. Thanks.

Any help would be appreciated... Im trying to get my wooden head
around this!!! Ive only been using VB.Net for about 7 days. (Was
tempted to go back to VB6 but Im trying to get out of my lazy ways! ;)
)

Thanks, (e-mail address removed)
 
R

Richard

(e-mail address removed) (John Tear) wrote in message
I can get clients to connect, send and receive data
ok but I cannot get the remote IP address.

When I say it doesnt work, it just doesnt work. When I add the
MessageBox.Show to try and grab the IP address the clients cannot even
connect! NO ERROR MESSAGES!!! >

Sorry John, Im abit confused you say you can get them to connect, but
then yu say you cant?

Post some of your calling code, it might be a timing issue....
esepecially if your aren't getting any errors, from memory no
exception is thrown when you try to read the IP address of a
disconnected/connecting... socket.


Do you get an empty messagebox or does that not even appear?

Richard
 
J

John Tear

OK, So Im getting a little p***ed off now! The previous method didnt
work so I try the following:


This is inside the client class:

Private mobjSocket As Socket

' initialize with a raw socket
Public Sub New(ByVal s As Socket)
mobjSocket = s
RaiseEvent Connected(Me)
mobjSocket.BeginReceive(marData, 0, 1024, SocketFlags.None,
AddressOf DoReceive, Nothing)

Dim ipaddress As System.Net.IPAddress ' raw Ip
m_ipaddress = ipaddress.Parse(CType(mobjSocket.RemoteEndPoint,
System.Net.IPEndPoint).Address.ToString()).ToString

End Sub

Public ReadOnly Property RemoteIPAddress() As String
Get
Return m_ipaddress
End Get
End Property


When I try to call it in an event:

Private Sub OnLineReceived(ByVal sender As Client, ByVal Data As
String)

MessageBox.Show(sender.RemoteIPAddress)

End Sub

Basically the event works, and I can accept connects, receive and send
data, everything seems fine but the messagebox shows... Guess what...
NOTHING!!!

Im either going to smash my PC into 10 million bits (get the joke?) or
Im going to give up programming forever! PLEASE HELP ME!!!

Thanks, (e-mail address removed)
 
R

Richard

Im either going to smash my PC into 10 million bits (get the joke?) or
Im going to give up programming forever! PLEASE HELP ME!!!

I'll email you my address just send me code through if it's not too
complex and bulky (winzip it) and i'll have alook.

If you do decide to smash up your PC can you set a web cast for it. I
love to see it. Ive always wanted to chuck a PC through a window or
smash a monitor up between the door and its frame.

I'll probably never to do it but if your going to then at least i
might be able to get some vicarious enjoyment out of the spectacle.

In fact.... maybe i wont help you... Is there anything i can do to
fuel your rage!! hahha

;)

Richard

*mailing u now*
 
J

John Tear

Im going to watch a football match today, if the home team lose
(Carlisle Utd) I think I might just do that.

Set up a little webcam and go to town with a 10 pound hammer!

On a serious note... PLEASE HELP ME!!!! SOMEBODY!!!!

(e-mail address removed)
 
M

MS public

When you say your messagebox shows nothing, do you mean it displays empty
text, or simply does not display at all ?

Regards - OHM
 
J

John Tear

Hi all

Finally got this sorted.

I was trying to get the remote IP address by using a TCPClient object
which I now know doesnt work!

I used the Socket object instead and this worked a treat. Thanks for
all your help.

....

RemoteIPAddress = IPAddress.Parse(CType(s.RemoteEndPoint,
IPEndPoint).Address.ToString()))

.... where s was a socket object

John T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top