A
A
andrkkk2020-04-16 14:36:37
C++ / C#
andrkkk, 2020-04-16 14:36:37

How on the client, using a broadcast request, find the server (Winsock)?

There is a server on the PC, I immediately launch the client (All via UDP). How to make a broadcast request to find the server, get its ip (well, here 127.0.0.1 and it will be in any case I think) and port to fill in the structure:

RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(Port);
RecvAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

and then communicate with this server. It is planned to launch several servers and choose one of them for further communication.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-04-16
@andrkkk

The client sends a broadcast (SO_BROADCAST) packet "Server, ay!" to the broadcast address of the network.
The server, having received such a request, sends directly to the client the packet "Ayushki?"
The client, having received such a response from the server, remembers the sender's address.
If several servers answered, then the client chooses the one he likes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question