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

Author Topic: How to properly close a sf::TcpSocket so that it's reusable?  (Read 2922 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
As the topic describes, how to do this?
I've just implemented a network handler for my game, and bound it to the games consoles commandlist as "connect" and "disconnect" wich simply connects and disconnects to a server.

But how to do this in nonblocking mode so that i can connect, then disconnect, and then connect again? I got an error when trying to connect to an already disconnected socket(first that socket wasnt ready, then when trying to do it again, its just error), so i simply made the socket a pointer instead of an object, and on the connect function i made it create a new tcpsocket, and on the disconnect i set it to NULL. This works, but is this really the proper way? Isn't there like a clear or reset function or something?

Maybe my methodics are wrong?

Here is the code for the clientside, the connect and disconnect functions(this works):

Connect: https://legacy.sfmluploads.org/index.php?page=view_code&id=48

Disconnect: https://legacy.sfmluploads.org/index.php?page=view_code&id=49

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to properly close a sf::TcpSocket so that it's reusable?
« Reply #1 on: July 16, 2011, 10:03:50 am »
Disconnect() then Connect() is supposed to work.

Can you please write a minimal and complete example that reproduces the problem, so that I can test it and fix the code if there's a bug?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
How to properly close a sf::TcpSocket so that it's reusable?
« Reply #2 on: July 16, 2011, 11:06:40 am »
Quote from: "Laurent"
Disconnect() then Connect() is supposed to work.

Can you please write a minimal and complete example that reproduces the problem, so that I can test it and fix the code if there's a bug?


Lol nevermind! It has to be some bug on my side. Narrowed down my code completely to just connect, send packet, and disconnect. And it totally works.

Well now i know i really have to look over my code, pretty new to networking ;p