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

Author Topic: Network functionality  (Read 26675 times)

0 Members and 1 Guest are viewing this topic.

DrEvil

  • Newbie
  • *
  • Posts: 21
    • View Profile
Network functionality
« on: November 04, 2007, 08:24:41 pm »
Please forgive me if I overlooked this functionality, but it seems that the networking classes are lacking some pretty important functionality.

Threading the networking is overkill for many projects, so I was a bit surprised that there aren't any non blocking variations of the socket functions.

Additionally, it appears there is very little in terms of error reporting available for the sockets.

How do you check if a socket is connected? Like a SocketTCP::IsConnected.
How do you tell when a socket gets disconnected? Just returning false from Recieve and such is rather basic. How about some wrapped access to the actual socket errors ?

The blocking stuff is the biggest issue at the moment for me. It's not worth threading my current app for networking. I'd rather keep it polling each update, but I can't do that with the sfml networking as is. Any plans to improve this soonish?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Network functionality
« Reply #1 on: November 05, 2007, 02:05:24 am »
Just look at the roadmap, the non-blocking option is already planned.

I agree, the network package needs some important improvements. But as it's the less used package, I get very little feedback and I can't improve it as fast as the other packages.

Thanks for your feedback.
Laurent Gomila - SFML developer

DrEvil

  • Newbie
  • *
  • Posts: 21
    • View Profile
Network functionality
« Reply #2 on: May 27, 2008, 07:08:26 am »
Checkin in again. I noticed the SetBlocking function has been added, so I've decided to give it another go.

So I SetBlocking(false) on a listener tcp socket, on the port I'm interested in. The problem now seems to be that SocketTCP::Accept doesn't return anything special to designate that there is no pending connection.

I would expect that when a non blocking listener socket is listening on a port, that each frame you can poll any pending connections and create them. At that point you'd have a SocketTCP for the clients connection, seperate of the listener socket. I presume that works if you use blocking sockets, but the non blocking socket support is incomplete in that regard, unless I'm missing something.

Calling SocketTCP.Accept on the non blocking listener socket right after Listen seems to return a normal error code(Done) as if it actually accepted a new connection immediately. I expect an immediate return, being non blocking, but how is the user expected to know when new client connections are opened?

Edit: Debugging a bit, it appears the problem is due to the

SetBlocking(true);

in the constructor SocketTCP::SocketTCP(SocketHelper::SocketType Descriptor)

When accept fails, with an error, this causes IsValid() to be == false, which causes SetBlocking to create a new socket with the following

// Make sure our socket is valid
    if (!IsValid())
        Create();

Simply remove the SetBlocking from that constructor and it allows Accept to properly fail and return NotReady

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Network functionality
« Reply #3 on: May 27, 2008, 06:14:03 pm »
I'm currently on holidays, but I'll check this as soon as I come back.

Thanks a lot for the details :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Network functionality
« Reply #4 on: June 12, 2008, 01:07:26 pm »
I managed fixed the bug, thanks :)

I didn't remove SetBlocking(true) from the constructor, but rather tested the validity of the socket before calling it.
Laurent Gomila - SFML developer

DrEvil

  • Newbie
  • *
  • Posts: 21
    • View Profile
Network functionality
« Reply #5 on: June 13, 2008, 06:19:58 pm »
Cool thanks

 

anything