I've recently done some socket programming and I'm wondering how to write a server browser for a game or application ( on a local network ).
I'm asking more for the design of this process, so pseudo code would appreciated.
If there are some abnormal features i should be aware of, I'm using pure C with Windows ( Winsock )
How would I go about this? Would I send a UDP packet to every single address on a local network and wait for a response to see if there is an actual server there?
If we assume that the server is required to receive updates from players and notify all players of player positions and so on, then:
1. Yes, you'll need a UDP server as there's no need for the overhead of TCP and the odd missed packet is tolerable.
2. Don't write it in C unless you have specific reasons to. You will be more productive in C++.
3. As you're on a local network, the server can broadcast single updates rather than sending separate messages to individual players. Larger networks can in principle use multicast, but most routers just aren't configured to support multicast.
4. The server will need to understand what a game is, track the players and their states, understand what updates are to be sent out and what to updates to expect from players.
Hmm...Thanks for a response, but it doesn't really answer my question ( sorry, i may not of worded it properly ).
Ive done some Socket programming before, but im looking at how to find a server on a local network.
E.g.
A friend is hosting a server on the local network, I go into my server browser and it will pop up on the feed of servers. How does my computer know that there is a server hosting on the local network?
Does my computer send out UDP packets to all addresses ( 192.168.1.1, 192.168.1.2, 192.168.1.3...etc ) and expects a response from one of the addresses? ( Server recieves packet and sends one back for connection )
This is more how to find and connect to the server in the first place rather than how to maintain a connection.
im looking at how to find a server on a local network
You can use some process of self discovery, but it's just easier to configure the server's address in the client. The server will get the client address when it receives a datagram (with recvfrom).
How does my computer know that there is a server hosting on the local network?
You tell it, and provide the server's IP address.
Does my computer send out UDP packets to all addresses ( 192.168.1.1, 192.168.1.2, 192.168.1.3...etc ) and expects a response from one of the addresses?
That's called broadcast. I would expect the server to broadcast updates, but the clients should only send updates to the server in the scheme I described above.
This is more how to find and connect to the server in the first place rather than how to maintain a connection.
You need to be clear on what your asking otherwise you're just wasting everyone's time.