Added optional argument on which address to bind (socket).
This commit is contained in:
parent
6b9781475d
commit
3a12fc6505
6 changed files with 100 additions and 61 deletions
|
@ -99,7 +99,7 @@ public:
|
|||
/// This constructor uses the internal representation of
|
||||
/// the address directly. It should be used for optimization
|
||||
/// purposes, and only if you got that representation from
|
||||
/// IpAddress::ToInteger().
|
||||
/// IpAddress::toInteger().
|
||||
///
|
||||
/// \param address 4 bytes of the address packed into a 32-bits integer
|
||||
///
|
||||
|
@ -182,15 +182,27 @@ public:
|
|||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const IpAddress None; ///< Value representing an empty/invalid address
|
||||
static const IpAddress Any; ///< Value representing any address (0.0.0.0)
|
||||
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
||||
static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network)
|
||||
|
||||
private:
|
||||
|
||||
friend SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resolve the given address string
|
||||
///
|
||||
/// \param address Address string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void resolve(const std::string& address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
|
||||
bool m_valid; ///< Is the address valid?
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -71,14 +72,15 @@ public:
|
|||
/// If the socket was previously listening to another port,
|
||||
/// it will be stopped first and bound to the new port.
|
||||
///
|
||||
/// \param port Port to listen for new connections
|
||||
/// \param port Port to listen for new connections
|
||||
/// \param address Address of the interface to listen on
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see accept, close
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status listen(unsigned short port);
|
||||
Status listen(unsigned short port, const IpAddress& address = IpAddress::Any);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Stop listening and close the socket
|
||||
|
|
|
@ -30,12 +30,12 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class IpAddress;
|
||||
class Packet;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -82,14 +82,15 @@ public:
|
|||
/// system to automatically pick an available port, and then
|
||||
/// call getLocalPort to retrieve the chosen port.
|
||||
///
|
||||
/// \param port Port to bind the socket to
|
||||
/// \param port Port to bind the socket to
|
||||
/// \param address Address of the interface to bind to
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see unbind, getLocalPort
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status bind(unsigned short port);
|
||||
Status bind(unsigned short port, const IpAddress& address = IpAddress::Any);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Unbind the socket from the local port to which it is bound
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue