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

Author Topic: how does a client find a computer running the server  (Read 7254 times)

0 Members and 1 Guest are viewing this topic.

garob

  • Guest
how does a client find a computer running the server
« on: January 03, 2012, 06:00:36 am »
Hi everyone,

I want to expand my game to play across multiple computers, the thing is I can't find any instructions on how to find a computer on the network that is running the server side. How does everyone solve his problem?

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how does a client find a computer running the server
« Reply #1 on: January 03, 2012, 08:05:33 am »
The solution is to use UDP broadcast: either the server sends "hello I'm the server" messages periodically to the whole network, or the client sends a "where is the server?" message when it wants to connect.
Laurent Gomila - SFML developer

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
how does a client find a computer running the server
« Reply #2 on: January 04, 2012, 06:31:26 pm »
You need to know the IP address of the computer running the server.

Otherwise, you can store the address in a MySQL data base when someone runs a server, and then get those addresses with the client. Use php + mysql and the HTTP client from SFML.

Cheers.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
how does a client find a computer running the server
« Reply #3 on: January 05, 2012, 12:53:47 am »
Well, for UDP broadcasts you won't need specific IPs, but you'll reach one subnet only (i.e. the usual "show LAN games" option).

Linuxxon

  • Newbie
  • *
  • Posts: 10
    • MSN Messenger - rasmus.linusson@gmail.com
    • View Profile
    • http://www.linuxxon.com
how does a client find a computer running the server
« Reply #4 on: January 22, 2012, 12:34:13 pm »
Think most people would broadcast the ip of the host throughout the network and then clients could pick up on that.

Don't know if sfml supports broadcasts but that's how most games and programs do it...

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
how does a client find a computer running the server
« Reply #5 on: January 23, 2012, 09:02:50 pm »
I'm trying to solve this problem, too. I can't find any way in SFML to send UDP broadcasts. Is it possible to do in SFML?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how does a client find a computer running the server
« Reply #6 on: January 23, 2012, 11:02:22 pm »
Quote
I can't find any way in SFML to send UDP broadcasts.

You're right, the low-level socket API defines the broadcast address to be the same as the "none" address, so SFML didn't make any difference between them.

I've changed the implementation so that the broadcast address is now valid and can be used.
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
how does a client find a computer running the server
« Reply #7 on: January 24, 2012, 11:53:44 pm »
Ah, good! So what is the broadcast address?

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
how does a client find a computer running the server
« Reply #8 on: January 25, 2012, 12:25:25 am »
Quote from: "JayArby"
Ah, good! So what is the broadcast address?

http://en.wikipedia.org/wiki/Broadcast_address

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
how does a client find a computer running the server
« Reply #9 on: January 25, 2012, 12:37:05 am »
Thanks for the reply, but it is nice to actually provide the information asked for rather than simply referencing a wikipedia article.

For the information of others, I understand from the article that the broadcast address for a local network is: 255.255.255.255

(Correct me if I got that wrong.)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how does a client find a computer running the server
« Reply #10 on: January 25, 2012, 10:33:09 am »
sf::IpAddress::Broadcast
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
how does a client find a computer running the server
« Reply #11 on: January 26, 2012, 05:24:58 am »
^ There's the answer I wanted to see! :D Thanks.

Beernutts

  • Newbie
  • *
  • Posts: 17
    • View Profile
how does a client find a computer running the server
« Reply #12 on: January 30, 2012, 08:32:00 pm »
Quote from: "JayArby"
Thanks for the reply, but it is nice to actually provide the information asked for rather than simply referencing a wikipedia article.

For the information of others, I understand from the article that the broadcast address for a local network is: 255.255.255.255

(Correct me if I got that wrong.)


I know this is a little late, but I wanted to make a point.

Julen26 was pointing you to a link that describes in detail what a broadcast address is and how it works.  He was getting you to learn about it yourself, since, if you have complete knowledge of a subject, you'll understand the why and how, not just the what, and that will make you a better programmer.

You know, teach a man to fish, and all that jazz.

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
how does a client find a computer running the server
« Reply #13 on: January 31, 2012, 04:03:04 am »
Yeah, it's good to provide a link, but only in addition to an answer. I see a lot of forums where someone asks for some information and he is bluntly told, "Try Google," or, "Check Wikipedia." That's just a way of saying, "You're stupid and I'm not going to help you."

I don't think that's what julen was trying to do, but I was just mentioning that it is more helpful for everyone who reads the post if a direct answer is given. After all, no one needs to be told how to look up a wikipedia article.

 

anything