Which user is sending the data? (winsock in VB)

Started by
6 comments, last by -Fruz- 22 years, 3 months ago
I'm wondering if there is a way to see wich IP that the data is comming from with winsock (not API) in VB? It doesn't need to be the IP, just a thing so I can see wich user data is comming from. Plz! JFK Edited by - -Fruz- on January 14, 2002 11:25:26 AM
Advertisement
I don't know how it maps to VB, but the function to get the name of the remote host connected to a given socket is 'getpeername' (maybe WSAGetPeerName or something when you use WinSock...).

Edited by - Fruny on January 14, 2002 11:45:34 AM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Look up the following Winsock control properties:

RemoteHost
RemoteHostIP
RemotePort

Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Hmmm... I don''t see how I can use these to get the user sending the data. You see.. If I have multiple clients on one host, it''s unlikely that you can use theese commands:

RemoteHost
RemoteHostIP
RemotePort
or
getpeername???

Cause it won''t know witch remote host or remote peer name!
If you use RemoteHost with multiple connections, You have to specify the it. That''s not what I wan''t :\

As i''m sure you know, It''s the DataArrivel function i''m using, and I can''t write:
---------------------------
winsock1.DataArrivel.....
If RemoteHost = ...... Then
---------------------------
Because winsock chooses 1 remotehost to deal with... Or? Hmmm... When I hink about it. It can''t do that either, because then it wouldn''t be possible with multiple connections... Hmmm... Plz! Help me!

JFK (Very confused)
are you using TCP/IP with the winsock control? if so, you can only have one client connected to the winsock at a time. if you want more clients connected, you need more winsock controls (there are tutorials out there that tell how to dynamically load and set up the winsock controls each time someone tries to connect). so, each client will have a separate winsock control, and you can use the "remotehost" properties (or just use the control index, as it will stay the same for each user until they disconnect).
if you are using UDP then i dunno...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
I''m using TCP/IP so I guess you are right... Thanx m8!
When using UDP you can obtain the information the same way but it is a bit more clumsy.

When you receive the DataArrival event when receiving UDP packets you must query for the RemoteHost/Port there. TCP/IP is different because it is connection oriented and as krez said its one "control" (socket) per connected client.

Hope you get things working.



Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Thanx for all the replies, but after some thinking I decide to use DirectPlay instead

This topic is closed to new replies.

Advertisement