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

Author Topic: My generic questions about network  (Read 3562 times)

0 Members and 1 Guest are viewing this topic.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
My generic questions about network
« on: April 04, 2016, 05:35:09 am »
Hello friends,
I don't have any problems really, I'm just looking for more experienced programmers to point me to the right direction. This is a little chat I've made using SFML + Dear ImGui. It works fine, it does what it is supposed to do, yet, I want to make sure to learn everything I can with this little program.

ChatSystem.h:
(click to show/hide)

ChatSystem.cpp:
(click to show/hide)

Keep in mind that I have 0 (zero) experience with network programming (not true since I got this chat working  ;D).

Question #1: I only have one socket that I use for everything, connecting, sending and receiving data. Since it is an unblocking socket, could that be a problem? What if I try to send something when it is receiving something? (the send function is not inside any loop).

Question #2: Do sockets have an internal queue or something? In unblocking mode, if I call receive (and there are things to receive) right after I call send, will it return NOT_READY on the second call if it's not done?

Question #3: I'm only able to connect with computers in LAN, why is that?

Question #4: I'm doing this as an exercise for something bigger, a turn-based strategy game. This is how I have the match-making in my mind:
- Player connects to server.
- Server is connected to all the players who are looking for match-making.
- Server says to player: "Hey, you and him are connected to me, which means you are both looking for a match. Here is his sf::IPAddress, try to connect with him."
- If successful, match starts.
- Then it's pretty much like a chat, where player send commands to each other.
Did I get it right? Is it really that simple (I should not say that, I know I'll regret)? What other concepts should I grasp?

Thanks!
« Last Edit: April 04, 2016, 06:48:40 pm by Tukimitzu »

nicox11

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: My generic questions about network
« Reply #1 on: April 04, 2016, 10:50:14 am »
Question 1 : I don't think there is any problem with this (you should maybe wait for a more experienced response).

Question 2 : Why don't you test it yourself ? :)

Question 3 : Check your firewall, this is surely the problem. Take in account that you need to open the specified port into your router if it has a firewall function. Make sure to use your public IP address (since you said you were beginner, we never know :) ).

Question 4 : I see some problem with your idea. I don't think player should be able to know their IP address and connect directly. This can lead to severe problems, especialy in an anonymous center. Instead, player shoudl always connect to the server, and then the server send back the data to the other player (allowing you to check for the validity of the data before sending it if you want, proventing your application from cheating systems). You can check the documentation of selector since it will surely do want you want.
« Last Edit: April 04, 2016, 12:08:13 pm by nicox11 »

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: My generic questions about network
« Reply #2 on: April 04, 2016, 04:36:40 pm »
Question 1 : I don't think there is any problem with this (you should maybe wait for a more experienced response).
Waiting...

Question 2 : Why don't you test it yourself ? :)
Is laziness a valid answer?

Question 3 : Check your firewall, this is surely the problem. Take in account that you need to open the specified port into your router if it has a firewall function. Make sure to use your public IP address (since you said you were beginner, we never know :) ).
Yep, I was using the local address  ;D

Question 4 : I see some problem with your idea. I don't think player should be able to know their IP address and connect directly. This can lead to severe problems, especialy in an anonymous center. Instead, player shoudl always connect to the server, and then the server send back the data to the other player (allowing you to check for the validity of the data before sending it if you want, proventing your application from cheating systems). You can check the documentation of selector since it will surely do want you want.
I understand the cheating possibility. But here is what I'm most concerned about: money. I don't even know if that's a big deal or not, I'm just trying to foresee my future, but if I make so that all the data being transferred within the players passes through a server to be processed first, I would need the server to be running in a better machine with a better internet connection, right? But if I have the server acting only as a hub where the match-making happens, I can run the server in a much cheaper machine.

Also, as far as I know, cheating will always be a possibility if the cheater is brave enough.

Thoughts?

nicox11

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: My generic questions about network
« Reply #3 on: April 04, 2016, 05:08:12 pm »
Question 4 : I see some problem with your idea. I don't think player should be able to know their IP address and connect directly. This can lead to severe problems, especialy in an anonymous center. Instead, player shoudl always connect to the server, and then the server send back the data to the other player (allowing you to check for the validity of the data before sending it if you want, proventing your application from cheating systems). You can check the documentation of selector since it will surely do want you want.
I understand the cheating possibility. But here is what I'm most concerned about: money. I don't even know if that's a big deal or not, I'm just trying to foresee my future, but if I make so that all the data being transferred within the players passes through a server to be processed first, I would need the server to be running in a better machine with a better internet connection, right? But if I have the server acting only as a hub where the match-making happens, I can run the server in a much cheaper machine.

Also, as far as I know, cheating will always be a possibility if the cheater is brave enough.

Thoughts?

Of course cheating will always be a possibility, but it'll be way harder with a central server. I told about cheating, but it's not the only problem. Letting player know about adversary IP address can leads to hacking issue (which is bad for your reputation). About the price, of course it costs more to launch a dedicated server for all player, but the server can simply act as a relay (just to not let player know adversary IP, and add simplistic cheating provention system that do not need a lot of cpu). What will be your requierements ? How many players will play at the same time ? A solution is to permit player to launch a server (so giving the "central server program").
Anyway, you can only make a hub server as you said, but take in consideration that it is maybe not the best (or maybe is ! But i don't see many negatives points launching a "central server").
« Last Edit: April 04, 2016, 05:15:59 pm by nicox11 »

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: My generic questions about network
« Reply #4 on: April 04, 2016, 05:39:41 pm »
Ok, you convinced me about the importance of a central server.
What I want to do is exactly what a game like Hearthstone does.
- It is a 1v1 turn-based strategy game, the player only needs to communicate with his adversary.
- There's no lobby, the match-making is a black box.
- The data transferred is not time critical, which is why I'm using TCP/IP.
- The data transferred is very small.

So how exactly does a server like this work? This is how I imagine:
- Player connects to server.
- Server matches 2 players together.
- Players start match.
- Whenever a player has some information to send to the other player, it says to the server: "Hey, I don't know who am I playing with (his IP Adress), but whoever it is, could you please send this to him?"
- Server says: "Sure buddy! Let me just check if you are cheating."

Is that right?

And also, considering the complexity of the calculations performed by this server in this scenario, and considering that the game is moderately successful (meaning there will be thousands of games happening in any given time) is renting a machine recommended? Or is there another solution?

Thanks!
« Last Edit: April 04, 2016, 05:43:46 pm by Tukimitzu »

nicox11

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: My generic questions about network
« Reply #5 on: April 04, 2016, 05:51:36 pm »
Ok, you convinced me about the importance of a central server.
What I want to do is exactly what a game like Hearthstone does.
- It is a 1v1 turn-based strategy game, the player only needs to communicate with his adversary.
- There's no lobby, the match-making is a black box.
- The data transferred is not time critical, which is why I'm using TCP/IP.
- The data transferred is very small.

So how exactly does a server like this work? This is how I imagine:
- Player connects to server.
- Server matches 2 players together.
- Players start match.
- Whenever a player has some information to send to the other player, it says to the server: "Hey, I don't know who am I playing with (his IP Adress), but whoever it is, could you please send this to him?"
- Server says: "Sure buddy! Let me just check if you are cheating."

Is that right?

And also, considering the complexity of the calculations performed by this server in this scenario, and considering that the game is moderately successful (meaning there will be thousands of games happening in any given time) is renting a machine recommended? Or is there another solution?

Thanks!

That's how I'd do it.

You have to find what will cost the most (in term of CPU). Checking for cheating ? (it seams no like a big deals since you say "The data transferred is very small" even if it doesn't necesseraly means it's easy) Pairing player ? Anyway, thousands of games happening, i don't see how you can handle this without a dedicated machine. Wait for experienced network developper, since I never made a game of this size.
« Last Edit: April 04, 2016, 05:53:38 pm by nicox11 »

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: My generic questions about network
« Reply #6 on: April 04, 2016, 06:48:18 pm »
Thanks for the help man, I might open other threads with more specific questions as the troubles come.  :)