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

Author Topic: SFML network library vs ?  (Read 16498 times)

0 Members and 2 Guests are viewing this topic.

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
SFML network library vs ?
« on: May 24, 2012, 10:26:38 pm »
Hey everyone, I just finished an operating systems class where we learned about sockets and did some basic network programming.
Over summer I want to continue working on some SFML games, and I want to implement multiplayer.
I was wondering:
-how many people use the SFML networking lib and if they recommend it
-or if I should stick to low level socket programming
-or if I should learn a libary like boost.asio
I guess I'm just curious about your experiences with the SFML networking lib and if I should dive into it or just go another route - ease of use is a big plus if that's the case
Thank you for any of your suggestions/tips in advance
« Last Edit: May 24, 2012, 10:28:20 pm by vro »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML network library vs ?
« Reply #1 on: May 24, 2012, 11:48:54 pm »
I never actually programmed anything in the network direction but I've read a few snippets here and ther.

It always depends on the complexity but since you're new to all of this, I think it won't get too complicated, thus SFML will be well suited. If you get to the limits of SFML (which I don't really know) it's better you'd use boost.asio. Juggling with low level socket stuff will probably be a pain in the ass and quite a bit of work to get it crossplatform.

So start with SFML and switch to ASIO if needed. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: SFML network library vs ?
« Reply #2 on: May 25, 2012, 04:54:43 am »
thanks for the response, spent a bit of time and did all the tutorials - really intuitive and easy to use. My only question is why does Socket.Receive receive a different port number than the one you specify when spending?

Like in the sfml sockets tutorial, you send using port 4567, but the server always prints out a different port number than that even though the communication is working

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML network library vs ?
« Reply #3 on: May 25, 2012, 08:07:17 am »
Quote
My only question is why does Socket.Receive receive a different port number than the one you specify when spending?
With UDP sockets, you're not connected to a single remote machine, you can send and receive to/from anyone, anywhere (and thus any port).
Laurent Gomila - SFML developer

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML network library vs ?
« Reply #4 on: May 27, 2012, 01:24:13 pm »
Quote
-or if I should stick to low level socket programming

SFML is already in my opinion a low-level socket programming library (as compared to RakNet or the like). 

Two very useful tools SFML provides however, are the SocketSelector (for handling multiple socket connections on the server side) and most importantly the Packet abstraction (as opposed to stream-based sockets on TCP). Additionally, SFML is fully cross-platform between Windows, Linux and Macintosh. For these reasons I would definitively recommend using SFML instead of implementing network on low-level OS functions.
« Last Edit: May 27, 2012, 01:26:05 pm by Zefz »

RedxDev

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • RedxDev
    • Email
Re: SFML network library vs ?
« Reply #5 on: June 03, 2012, 05:36:34 pm »
The only real downside to using SFML for a multiplayer game is that TCP isn't that fast (though depending on the game, that might not matter) and SFML doesn't provide reliable UDP. If you do need a fast reliable network system, I suggest enet (which is pretty simple on its own).
My Website and blog - http://redxdev.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML network library vs ?
« Reply #6 on: June 03, 2012, 05:58:13 pm »
Reliable UDP is rarely needed. Usually, code that relies on UDP can handle (implicitely or explicitely) packet loss.

I just wanted to say this, so that unexperienced readers don't think that it is mandatory to implement a reliable layer on top of UDP.
Laurent Gomila - SFML developer

RedxDev

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • RedxDev
    • Email
Re: SFML network library vs ?
« Reply #7 on: June 03, 2012, 07:45:23 pm »
Yeah, you don't always need it, especially if you use TCP for the more important messages (like game events) and UDP for things like position updates.
My Website and blog - http://redxdev.com

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: SFML network library vs ?
« Reply #8 on: June 03, 2012, 08:11:02 pm »
isn't it bad practice to use both udp and tcp? at least that's what the tutorials at gafferongames.com say

RedxDev

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • RedxDev
    • Email
Re: SFML network library vs ?
« Reply #9 on: June 03, 2012, 08:45:18 pm »
No, it isn't. Many high-profile multiplayer games use both. It just makes things more complicated.
My Website and blog - http://redxdev.com

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: SFML network library vs ?
« Reply #10 on: June 03, 2012, 11:03:24 pm »
He didn't go into detail but: "TCP tends to induce packet loss in UDP packets". He did link to an article that does: http://www.isoc.org/INET97/proceedings/F3/F3_1.HTM

Maybe it doesn't produce a large enough effect to matter, I don't know, I'm just curious as I'm currently learning/trying to implement netcode in my game

RedxDev

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • RedxDev
    • Email
Re: SFML network library vs ?
« Reply #11 on: June 04, 2012, 05:43:45 pm »
I've never heard of that being true (that doesn't mean it isn't), but one program using both protocols won't make it any worse, since in all likelihood all computers on a network are using both anyway. That article talks about TCP and UDP being used at the same time, but not by the same program or even computer. Its talking about using them at the same time in the same network. If you really want to avoid packet loss, then you shouldn't run any web browsers when playing games on any computer on your network.

And honestly, if many multiplayer games use both and don't have problems, then it won't be a problem except for the fact that it does complicate things.

I believe Source engine uses both TCP and UDP (TF2, L4D, L4D2, CS:S, Portal 2 Co-op, Garry's Mod, and a bunch more).
My Website and blog - http://redxdev.com

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: SFML network library vs ?
« Reply #12 on: June 04, 2012, 09:37:12 pm »
Considering it's an ISOC article it probably holds some kind of truth, but skimming over it again it sounds like it only comes into effect if/when the TCP window grows to a certain size, which probably rarely happens?

I still kinda had the same feelings as you, since I know of a lot of games that use both, but then after reading that tutorial and that article I was kind of wondering

RedxDev

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • RedxDev
    • Email
Re: SFML network library vs ?
« Reply #13 on: June 04, 2012, 10:26:49 pm »
It probably is true, but you have to realize that whatever they say, it has to be put into perspective. That article talks about a worst-case scenario, and TCP and UDP are used together all the time without problems. So 1 or 2 extra UDP packets are dropped because of it. A program using UDP should be set up to handle dropped packets anyway.

Still, use whatever you think will fit with your project. If you need both reliable communication and fast communication, then use TCP and UDP, or use a library like enet that handles UDP packet loss (or make your own!). If you just need it to be fast, use UDP. If you only need reliability and the slowness of TCP isn't too bad for your project, then by all means, use it.
My Website and blog - http://redxdev.com

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: SFML network library vs ?
« Reply #14 on: June 05, 2012, 01:13:13 am »
(or make your own!)

That's what I'm currently working on :P
Well, on top of SFML.