diff --git a/include/SFML/Network/TcpListener.hpp b/include/SFML/Network/TcpListener.hpp index 840a7cde1..e0e05d64e 100644 --- a/include/SFML/Network/TcpListener.hpp +++ b/include/SFML/Network/TcpListener.hpp @@ -65,14 +65,16 @@ public: unsigned short getLocalPort() const; //////////////////////////////////////////////////////////// - /// \brief Start listening for connections + /// \brief Start listening for incoming connection attempts /// - /// This functions makes the socket listen to the specified - /// port, waiting for new connections. - /// If the socket was previously listening to another port, - /// it will be stopped first and bound to the new port. + /// This function makes the socket start listening on the + /// specified port, waiting for incoming connection attempts. /// - /// \param port Port to listen for new connections + /// If the socket is already listening on a port when this + /// function is called, it will stop listening on the old + /// port before starting to listen on the new port. + /// + /// \param port Port to listen on for incoming connection attempts /// \param address Address of the interface to listen on /// /// \return Status code diff --git a/include/SFML/Network/TcpSocket.hpp b/include/SFML/Network/TcpSocket.hpp index 6c0c8bc7f..6c0ab98aa 100644 --- a/include/SFML/Network/TcpSocket.hpp +++ b/include/SFML/Network/TcpSocket.hpp @@ -97,7 +97,8 @@ public: /// In blocking mode, this function may take a while, especially /// if the remote peer is not reachable. The last parameter allows /// you to stop trying to connect after a given timeout. - /// If the socket was previously connected, it is first disconnected. + /// If the socket is already connected, the connection is + /// forcibly disconnected before attempting to connect again. /// /// \param remoteAddress Address of the remote peer /// \param remotePort Port of the remote peer diff --git a/include/SFML/Network/UdpSocket.hpp b/include/SFML/Network/UdpSocket.hpp index 20e35b8b6..7ce3fe559 100644 --- a/include/SFML/Network/UdpSocket.hpp +++ b/include/SFML/Network/UdpSocket.hpp @@ -82,6 +82,11 @@ public: /// system to automatically pick an available port, and then /// call getLocalPort to retrieve the chosen port. /// + /// Since the socket can only be bound to a single port at + /// any given moment, if it is already bound when this + /// function is called, it will be unbound from the previous + /// port before being bound to the new one. + /// /// \param port Port to bind the socket to /// \param address Address of the interface to bind to /// diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index ce62fe767..399f87d63 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -63,6 +63,9 @@ unsigned short TcpListener::getLocalPort() const //////////////////////////////////////////////////////////// Socket::Status TcpListener::listen(unsigned short port, const IpAddress& address) { + // Close the socket if it is already bound + close(); + // Create the internal socket if it doesn't exist create(); diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index bb3e65c5e..e11f76b22 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -118,6 +118,9 @@ unsigned short TcpSocket::getRemotePort() const //////////////////////////////////////////////////////////// Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout) { + // Disconnect the socket if it is already connected + disconnect(); + // Create the internal socket if it doesn't exist create(); diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 99b52fdfe..0ff03b048 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -66,6 +66,9 @@ unsigned short UdpSocket::getLocalPort() const //////////////////////////////////////////////////////////// Socket::Status UdpSocket::bind(unsigned short port, const IpAddress& address) { + // Close the socket if it is already bound + close(); + // Create the internal socket if it doesn't exist create();