Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking clients and servers on a local network  (Read 4612 times)

0 Members and 1 Guest are viewing this topic.

watarok

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking clients and servers on a local network
« on: March 30, 2014, 08:55:35 am »
I have a system where clients are meant to connect to a server located on the LAN. It seems unreasonable for users to have to enter the address and port of a server, so I was planning on using broadcasting. The problem I'm facing is how it's possible to make all clients aware of all available servers.

As far as I'm aware, broadcasting only sends to a specific port on each computer. This seems to mean that either all of the clients or all of the servers need to have a common port number. Logically, there would be less servers, and it's more likely that they'll be able to bind to a shared port. This is still unreliable and limits each computer to a single server. Is there a better solution that I'm missing?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking clients and servers on a local network
« Reply #1 on: March 30, 2014, 09:38:07 am »
Using multiple servers on the same machine / port is not usual. Why would you need to do that?
Laurent Gomila - SFML developer

watarok

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Linking clients and servers on a local network
« Reply #2 on: March 30, 2014, 05:50:50 pm »
Using multiple servers on the same machine / port is not usual. Why would you need to do that?

I agree, I don't know when it would be necessary to have multiple servers on one machine, but it seemed like I should try to leave the possibility open.

What I meant by sharing a port is that each server, regardless of machine, would have the same port number. This was only necessary because, as I understand it, a client should broadcast a request for available servers. This would be sent to each machine, but only to the specified port on each. This is why I thought that servers would have to have a common port number.

If this is not the case, by all means correct me. :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking clients and servers on a local network
« Reply #3 on: March 30, 2014, 08:24:32 pm »
This is correct, but using more than one server per machine per port is really strange, both design-wise and technically. You should not do that if you don't need to. The port is what allows to route stuff to the right recipient. Declaring more than one recipient on the same port defeats this point. I don't even know if you would get the expected behaviour on every OS if you tried to do it anyway.
« Last Edit: March 30, 2014, 08:27:47 pm by Laurent »
Laurent Gomila - SFML developer

watarok

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Linking clients and servers on a local network
« Reply #4 on: March 31, 2014, 01:41:37 am »
Sorry that I'm being unclear, but I'm not trying to have multiple servers running with the same port on the same machine. What I was wondering was how to best make clients and servers aware of each other.

When broadcasting, you can send to all computers, but you still have to specify a port number, say 8025. If the client broadcasts a request for servers, I believe that all of the servers on any machine in the network would have to be on port 8025 for them to receive the client's request.

The problem with this is that if port 8025 is being used by some other program, then that machine cannot run the server. This therefore doesn't seem like a great method to ensure connection between clients and servers.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Linking clients and servers on a local network
« Reply #5 on: March 31, 2014, 01:57:19 am »
So you want to query multiple ports, aka port scanning? It is typical for applications to agree on a port, but if really necessary you can specify some fallback ports if one is occupied. However, scanning the whole port range eats up a lot of bandwidth and can be quickly regarded as a malicious attack. It depends on your network whether that is appropriate.

By the way, are you bound to TCP?
« Last Edit: March 31, 2014, 01:59:57 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

watarok

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Linking clients and servers on a local network
« Reply #6 on: March 31, 2014, 05:10:38 am »
By the way, are you bound to TCP?

No, I've used UDP in the past.
The system I've previously used involved the client prompting the user for the address and port number of a server to which it would then send a request to connect.

Ideally, the user should be given a list of available servers on the network. My plan was to accomplish this by broadcasting. This would give two options: the servers must advertise their presence, or the clients must send a request to which the server(s) would respond. Since it doesn't seem like a good idea for servers to constantly broadcast, I would have the client send an individual broadcast to the servers. To this end, I would need to specify a port to which the client's request would be sent on each machine. This same port number would have to be used by each server for them to receive the client's message and to reply. The only problem I found with this approach was that a server could not use another port if the specified one is taken.

I'm wondering if there's any flaw in my approach or if there's a better alternative for a client to receive a list of servers.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking clients and servers on a local network
« Reply #7 on: March 31, 2014, 07:50:42 am »
I think this is the most common technique. If the server cannot use its standard port for some reason,  it's always possible to specify it on client side.
Laurent Gomila - SFML developer

Vauteck

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Linking clients and servers on a local network
« Reply #8 on: March 31, 2014, 02:17:31 pm »
Ok so basically you want to implement a list of available servers for multiplayer mode (at least that's what I understand).
The broadcast method you described would only work on LAN, not internet (since broadcast messages are not forwarded).
I think the standard way of doing this is to have a "master" server that registers all servers. When you create a server on your local machine, it needs to make a register query to the master server. If the master server identifies the register request as valid, it adds the server to its online servers list.

As a client, you simply make a query to the master server to get the list of all available servers.

A basic server is a combination of an IP address and a port, which then allows to host multiple servers on the same machines with differents ports.

Hope this answers your question.

Cheers

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking clients and servers on a local network
« Reply #9 on: March 31, 2014, 02:39:38 pm »
Quote
The broadcast method you described would only work on LAN, not internet
Read his first post carefully, it starts with this:

Quote
clients are meant to connect to a server located on the LAN

So he definitely doesn't need a master server ;)
Laurent Gomila - SFML developer

Vauteck

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Linking clients and servers on a local network
« Reply #10 on: March 31, 2014, 03:30:01 pm »
Quote
So he definitely doesn't need a master server ;)

I wouldn't rule out the master server solution so fast imho ^^.

First, it's unclear what his needs are ; whilst I agree he stated it's for LAN use at the moment, the broadcast solution has a severe pitfall in that it limits the number of server instances to one per computer. To get rid of that limitation, you can either broadcast to multiple ports (but you're still limited to the number of broadcast messages you send), or you can use an external source to gather infos about ongoing servers.

Secondly, the master server solution scales better (internet, lots of server on LAN, etc...) and is a "cleaner" solution imho ;D.

To sum it up :
      broadcast  => easy and fast to implement (but some limitations).
      master server => more code / logic to implement, but cleaner imho^^.

Cheers

watarok

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Linking clients and servers on a local network
« Reply #11 on: April 01, 2014, 03:31:54 am »
Thanks for all of the responses.  :D

I think I'll end up using the broadcasting method due to its simplicity and the small scope of my project. I'll keep the master server idea in mind for more serious projects or for non-local connections.