|
-
May 10th, 2003, 01:35 AM
#1
Thread Starter
Registered User
Sockets?!
hello,
in this program that i want a client has to connect to a server in a small workgroup , without knowing the ip address of the computer where the server( listener ) is installed . is there a way for the client to broadcast to all computers and find the listener???
( the computers get there ip from a dhcp server, i know i can use the host name of the server , but the server program might be moved from a computer to another, so the answer of the question above will solve my problems)
thanks ...
-
May 10th, 2003, 08:46 AM
#2
Hyperactive Member
I think Yes... Assuming Lan addresses are 192.168.0.X you can do a for cicle like so:
VB Code:
Function FindListener() as integer
for x=0 to 255
try
'Try to connect, ensure you connected to your listener
'by exchanging some messages...
socket.Connect("192.168.0."+x.tostring())' Don't remember ther right instruction...
' This is only an example...
If ListenerIsright then return x
catch e as exception
end try
next x
end function
Learn, this is the Keyword...
-
May 10th, 2003, 08:59 AM
#3
Thread Starter
Registered User
in this case i'm using TCPCLIENT , and theres one listener, so this code is going to throw 255 exceptions, any other way?!
I know theres an ip address ( i think 255.255.255.255 ) that broadcasts messages, is there a way to use that to solve my problem?!
thanks again...
-
May 10th, 2003, 09:32 AM
#4
Hyperactive Member
Yes, that code will throw a maximum of 256 exception if tcplistener is not found, but it doesn't matter, you catch them all...
I don't know if you can use 255.255.255.255... Maybe someone else can say...
Learn, this is the Keyword...
-
May 10th, 2003, 09:37 AM
#5
Thread Starter
Registered User
i've started to write the program in Xmas79 's way, anyone else with other idea's?
I want to find a remote listener in a workgroup, plz let me know how you would do it, thanks
-
May 10th, 2003, 11:11 AM
#6
Fanatic Member
You have a couple of options.
1) Use broadcasting as you're thinking, although you should be wary of the fact that nearly all network admins set their equipment to drop broadcast packets at the router (and sometimes the switch) level.
2) Use a configuration file that points to the server that is set at installation time
3) Prompt the user at some point and store that in a config file
4) Obtain a list of good candidates from the Browser service of some computer (possibly the local workstation) via the NetServerEnum Windows API call and then contact each of them one at a time. Docs for NetServerEnum:
ms-help://MS.VSCC/MS.MSDNVS/netmgmt/ntlmapi2_1vl9.htm
5) Periodically have the SERVER poke around in people's configurations using WMI or registry settings and look for installed clients, and when it finds a client it configures it to point to the server. This is probably the least desirable.
Option 1 is probably the best combination of simple and effective, and you already have a head start on it. Good luck!
-
May 10th, 2003, 02:00 PM
#7
Junior Member
To find the server you can use multicast to get the listener to respond back.
Multicast can broadcast without excpecting anything back.
1. create a UDP Multicast listener on the server on a specified port.
3. Start a listener on the client to listen on incomming connections to give the client an IP from the Server.
2. Send a UDP Multicast packet from the client with the connection information you need. (Multicast can go through 50 routers).
3. The server recieves the multicast, and analyzes the packet (your connection data), and sends an IP packet back to the listener on the client to give the client an IP to start communicate.
Thats it.
There are several UDP multicast examples in this forum to start with.
I've used UDP multicast in my applications, and had big success with it.
Manpowre
-
May 10th, 2003, 02:30 PM
#8
Fanatic Member
Just have to be aware that multicast and broadcast traffic will almost certainly be dropped at the router level, and very likely at the switch level too (i.e. won't go across subnets). So if your workgroup or domain extends across multiple subnets, this will give you problems.
-
May 11th, 2003, 08:14 AM
#9
Thread Starter
Registered User
can u please link me to somewhere that explains a little more about this multicasting, and it would be great if i see some code
thanks ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|