I have a client-server thing where I am the server and the clients need to connect to me. But the ips on the network change all the time so its not really reliable to hardcode it in the program. How would i go about doing this? Thanks for any answers
Asked
Active
Viewed 440 times
0
-
1If you could only use names instead of numbers... oh wait - YOU CAN! :-D – Rob May 09 '17 at 12:46
-
Thats the thing i can't really use a dns on the network – Grivai May 09 '17 at 12:46
-
is this LAN? WAN? would UDP broadcast be an option, or does it need to be targetted? – Marc Gravell May 09 '17 at 12:47
-
Maybe using NETBIOS names? – Webbanditten May 09 '17 at 12:47
-
I assume you need the "address" of the server and not the ones of the clients., am I right? – Stefan May 09 '17 at 12:47
-
@MarcGravell Yes it is a LAN. But it would need to be tcp – Grivai May 09 '17 at 12:48
-
@Stefan Yes i need the address of the server – Grivai May 09 '17 at 12:48
-
Ok, normally you do this by hostname. If somehow you can't because ... some dark mysterious reason... you can fix the IP of the server. – Stefan May 09 '17 at 12:49
-
@Webbanditten I can't really use NETBIOS either. Men tak for svaret :) – Grivai May 09 '17 at 12:50
-
Can you try this one?: http://stackoverflow.com/questions/22852781/c-sharp-how-to-do-network-discovery-using-udp-broadcast – Stefan May 09 '17 at 12:53
-
@Stefan Thanks this is better than the solution I found :). And it was just an idea where I could have an external server where the ip could be static and it would contact that for the ip but this is better. – Grivai May 09 '17 at 12:55
1 Answers
0
You can use UDP to respond first request of the client with TCP ip details to connect server , Every client request must connect first time with the UDP then its establish the TCP connection

Mohan
- 1
- 2