Improved the API documentation of sf::IpAddress
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1452 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
b7eb09cb79
commit
e924c9cf39
@ -223,11 +223,11 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Network\IPAddress.cpp"
|
RelativePath="..\..\src\SFML\Network\IpAddress.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\include\SFML\Network\IPAddress.h"
|
RelativePath="..\..\include\SFML\Network\IpAddress.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -222,11 +222,11 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Network\IPAddress.cpp"
|
RelativePath="..\..\src\SFML\Network\IpAddress.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\include\SFML\Network\IPAddress.h"
|
RelativePath="..\..\include\SFML\Network\IpAddress.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\..\include\SFML\Network\Ftp.h" />
|
<Unit filename="..\..\include\SFML\Network\Ftp.h" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Http.h" />
|
<Unit filename="..\..\include\SFML\Network\Http.h" />
|
||||||
<Unit filename="..\..\include\SFML\Network\IPAddress.h" />
|
<Unit filename="..\..\include\SFML\Network\IpAddress.h" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Packet.h" />
|
<Unit filename="..\..\include\SFML\Network\Packet.h" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Selector.h" />
|
<Unit filename="..\..\include\SFML\Network\Selector.h" />
|
||||||
<Unit filename="..\..\include\SFML\Network\SocketStatus.h" />
|
<Unit filename="..\..\include\SFML\Network\SocketStatus.h" />
|
||||||
@ -67,7 +67,7 @@
|
|||||||
<Unit filename="..\..\src\SFML\Network\FtpStruct.h" />
|
<Unit filename="..\..\src\SFML\Network\FtpStruct.h" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Http.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Http.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\HttpStruct.h" />
|
<Unit filename="..\..\src\SFML\Network\HttpStruct.h" />
|
||||||
<Unit filename="..\..\src\SFML\Network\IPAddress.cpp" />
|
<Unit filename="..\..\src\SFML\Network\IpAddress.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Packet.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Packet.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\PacketStruct.h" />
|
<Unit filename="..\..\src\SFML\Network\PacketStruct.h" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Selector.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Selector.cpp" />
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/System.h>
|
#include <SFML/System.h>
|
||||||
#include <SFML/Network/IPAddress.h>
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/Packet.h>
|
#include <SFML/Network/Packet.h>
|
||||||
#include <SFML/Network/Selector.h>
|
#include <SFML/Network/Selector.h>
|
||||||
#include <SFML/Network/SocketTCP.h>
|
#include <SFML/Network/SocketTCP.h>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.h>
|
#include <SFML/Config.h>
|
||||||
#include <SFML/Network/IPAddress.h>
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/Types.h>
|
#include <SFML/Network/Types.h>
|
||||||
|
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ CSFML_API void sfFtp_Destroy(sfFtp* ftp);
|
|||||||
/// \return Server response to the request
|
/// \return Server response to the request
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIPAddress server, unsigned short port, float timeout);
|
CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Log in using anonymous account
|
/// Log in using anonymous account
|
||||||
|
@ -32,12 +32,12 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// sfIPAddress provides easy manipulation of IP v4 addresses
|
/// sfIpAddress provides easy manipulation of IP v4 addresses
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char Address[16];
|
char Address[16];
|
||||||
} sfIPAddress;
|
} sfIpAddress;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -48,7 +48,7 @@ typedef struct
|
|||||||
/// \return Resulting address
|
/// \return Resulting address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_FromString(const char* string);
|
CSFML_API sfIpAddress sfIpAddress_FromString(const char* string);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct an address from 4 bytes
|
/// Construct an address from 4 bytes
|
||||||
@ -61,7 +61,7 @@ CSFML_API sfIPAddress sfIPAddress_FromString(const char* string);
|
|||||||
/// \return Resulting address
|
/// \return Resulting address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3);
|
CSFML_API sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a 32-bits integer
|
/// Construct the address from a 32-bits integer
|
||||||
@ -69,7 +69,7 @@ CSFML_API sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint
|
|||||||
/// \param address : 4 bytes of the address packed into a 32-bits integer
|
/// \param address : 4 bytes of the address packed into a 32-bits integer
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_FromInteger(sfUint32 address);
|
CSFML_API sfIpAddress sfIpAddress_FromInteger(sfUint32 address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Tell if an address is a valid one
|
/// Tell if an address is a valid one
|
||||||
@ -79,7 +79,7 @@ CSFML_API sfIPAddress sfIPAddress_FromInteger(sfUint32 address);
|
|||||||
/// \return sfTrue if address has a valid syntax
|
/// \return sfTrue if address has a valid syntax
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfBool sfIPAddress_IsValid(sfIPAddress address);
|
CSFML_API sfBool sfIpAddress_IsValid(sfIpAddress address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a string representation of an address
|
/// Get a string representation of an address
|
||||||
@ -88,7 +88,7 @@ CSFML_API sfBool sfIPAddress_IsValid(sfIPAddress address);
|
|||||||
/// \param string : Char array to fill (size must be >= 16)
|
/// \param string : Char array to fill (size must be >= 16)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API void sfIPAddress_ToString(sfIPAddress address, char* string);
|
CSFML_API void sfIpAddress_ToString(sfIpAddress address, char* string);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get an integer representation of the address
|
/// Get an integer representation of the address
|
||||||
@ -98,7 +98,7 @@ CSFML_API void sfIPAddress_ToString(sfIPAddress address, char* string);
|
|||||||
/// \return 32-bits integer containing the 4 bytes of the address, in system endianness
|
/// \return 32-bits integer containing the 4 bytes of the address, in system endianness
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfUint32 sfIPAddress_ToInteger(sfIPAddress address);
|
CSFML_API sfUint32 sfIpAddress_ToInteger(sfIpAddress address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's local IP address (from the LAN point of view)
|
/// Get the computer's local IP address (from the LAN point of view)
|
||||||
@ -106,7 +106,7 @@ CSFML_API sfUint32 sfIPAddress_ToInteger(sfIPAddress address);
|
|||||||
/// \return Local IP address
|
/// \return Local IP address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_GetLocalAddress();
|
CSFML_API sfIpAddress sfIpAddress_GetLocalAddress();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's public IP address (from the web point of view).
|
/// Get the computer's public IP address (from the web point of view).
|
||||||
@ -119,7 +119,7 @@ CSFML_API sfIPAddress sfIPAddress_GetLocalAddress();
|
|||||||
/// \return Public IP address
|
/// \return Public IP address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_GetPublicAddress(float timeout);
|
CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(float timeout);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's loopback address
|
/// Get the computer's loopback address
|
||||||
@ -127,7 +127,7 @@ CSFML_API sfIPAddress sfIPAddress_GetPublicAddress(float timeout);
|
|||||||
/// \return Local host IP address (127.0.0.1, or "localhost")
|
/// \return Local host IP address (127.0.0.1, or "localhost")
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfIPAddress sfIPAddress_LocalHost();
|
CSFML_API sfIpAddress sfIpAddress_LocalHost();
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IPADDRESS_H
|
#endif // SFML_IPADDRESS_H
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.h>
|
#include <SFML/Config.h>
|
||||||
#include <SFML/Network/IPAddress.h>
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/SocketStatus.h>
|
#include <SFML/Network/SocketStatus.h>
|
||||||
#include <SFML/Network/Types.h>
|
#include <SFML/Network/Types.h>
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ CSFML_API void sfSocketTCP_SetBlocking(sfSocketTCP* socket, sfBool blocking);
|
|||||||
/// \return sfTrue if operation has been successful
|
/// \return sfTrue if operation has been successful
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIPAddress host, float timeout);
|
CSFML_API sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIpAddress host, float timeout);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Listen to a specified port for incoming data or connections
|
/// Listen to a specified port for incoming data or connections
|
||||||
@ -106,7 +106,7 @@ CSFML_API sfBool sfSocketTCP_Listen(sfSocketTCP* socket, unsigned short port);
|
|||||||
/// \return Socket status
|
/// \return Socket status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIPAddress* address);
|
CSFML_API sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIpAddress* address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send an array of bytes to the host (must be connected first)
|
/// Send an array of bytes to the host (must be connected first)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.h>
|
#include <SFML/Config.h>
|
||||||
#include <SFML/Network/IPAddress.h>
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/SocketStatus.h>
|
#include <SFML/Network/SocketStatus.h>
|
||||||
#include <SFML/Network/Types.h>
|
#include <SFML/Network/Types.h>
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ CSFML_API sfBool sfSocketUDP_Unbind(sfSocketUDP* socket);
|
|||||||
/// \return Socket status
|
/// \return Socket status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIPAddress address, unsigned short port);
|
CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIpAddress address, unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Receive an array of bytes.
|
/// Receive an array of bytes.
|
||||||
@ -120,7 +120,7 @@ CSFML_API sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data,
|
|||||||
/// \return Socket status
|
/// \return Socket status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIPAddress* address, unsigned short* port);
|
CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send a packet of data
|
/// Send a packet of data
|
||||||
@ -133,7 +133,7 @@ CSFML_API sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, si
|
|||||||
/// \return Socket status
|
/// \return Socket status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress address, unsigned short port);
|
CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress address, unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Receive a packet.
|
/// Receive a packet.
|
||||||
@ -148,7 +148,7 @@ CSFML_API sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* p
|
|||||||
/// \return Socket status
|
/// \return Socket status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_API sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress* address, unsigned short* port);
|
CSFML_API sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Close the socket
|
/// Close the socket
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Ftp.h>
|
#include <SFML/Network/Ftp.h>
|
||||||
#include <SFML/Network/FtpStruct.h>
|
#include <SFML/Network/FtpStruct.h>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
|
|
||||||
|
|
||||||
@ -197,11 +197,11 @@ void sfFtp_Destroy(sfFtp* ftp)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Connect to the specified FTP server
|
/// Connect to the specified FTP server
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIPAddress server, unsigned short port, float timeout)
|
sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(ftp, NULL);
|
CSFML_CHECK_RETURN(ftp, NULL);
|
||||||
|
|
||||||
sf::IPAddress SFMLServer(server.Address);
|
sf::IpAddress SFMLServer(server.Address);
|
||||||
|
|
||||||
return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, timeout));
|
return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, timeout));
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/IPAddress.h>
|
#include <SFML/Network/IpAddress.h>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ namespace
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Helper function for converting a SFML address to a CSFML one
|
/// Helper function for converting a SFML address to a CSFML one
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress FromSFMLAddress(sf::IPAddress address)
|
sfIpAddress FromSFMLAddress(sf::IpAddress address)
|
||||||
{
|
{
|
||||||
sfIPAddress result;
|
sfIpAddress result;
|
||||||
strncpy(result.Address, address.ToString().c_str(), 16);
|
strncpy(result.Address, address.ToString().c_str(), 16);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -46,9 +46,9 @@ namespace
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Helper function for converting a CSFML address to a SFML one
|
/// Helper function for converting a CSFML address to a SFML one
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::IPAddress ToSFMLAddress(sfIPAddress address)
|
sf::IpAddress ToSFMLAddress(sfIpAddress address)
|
||||||
{
|
{
|
||||||
return sf::IPAddress(address.Address);
|
return sf::IpAddress(address.Address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,34 +56,34 @@ namespace
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct an address from a string
|
/// Construct an address from a string
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_FromString(const char* string)
|
sfIpAddress sfIpAddress_FromString(const char* string)
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress(string));
|
return FromSFMLAddress(sf::IpAddress(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct an address from 4 bytes
|
/// Construct an address from 4 bytes
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3)
|
sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3)
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress(byte0, byte1, byte2, byte3));
|
return FromSFMLAddress(sf::IpAddress(byte0, byte1, byte2, byte3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a 32-bits integer
|
/// Construct the address from a 32-bits integer
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_FromInteger(sfUint32 address)
|
sfIpAddress sfIpAddress_FromInteger(sfUint32 address)
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress(address));
|
return FromSFMLAddress(sf::IpAddress(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Tell if an address is a valid one
|
/// Tell if an address is a valid one
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfBool sfIPAddress_IsValid(sfIPAddress address)
|
sfBool sfIpAddress_IsValid(sfIpAddress address)
|
||||||
{
|
{
|
||||||
return ToSFMLAddress(address).IsValid() ? sfTrue : sfFalse;
|
return ToSFMLAddress(address).IsValid() ? sfTrue : sfFalse;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ sfBool sfIPAddress_IsValid(sfIPAddress address)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a string representation of an address
|
/// Get a string representation of an address
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void sfIPAddress_ToString(sfIPAddress address, char* string)
|
void sfIpAddress_ToString(sfIpAddress address, char* string)
|
||||||
{
|
{
|
||||||
if (string)
|
if (string)
|
||||||
strcpy(string, address.Address);
|
strcpy(string, address.Address);
|
||||||
@ -102,7 +102,7 @@ void sfIPAddress_ToString(sfIPAddress address, char* string)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get an integer representation of the address
|
/// Get an integer representation of the address
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfUint32 sfIPAddress_ToInteger(sfIPAddress address)
|
sfUint32 sfIpAddress_ToInteger(sfIpAddress address)
|
||||||
{
|
{
|
||||||
return ToSFMLAddress(address).ToInteger();
|
return ToSFMLAddress(address).ToInteger();
|
||||||
}
|
}
|
||||||
@ -111,9 +111,9 @@ sfUint32 sfIPAddress_ToInteger(sfIPAddress address)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's local IP address (from the LAN point of view)
|
/// Get the computer's local IP address (from the LAN point of view)
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_GetLocalAddress()
|
sfIpAddress sfIpAddress_GetLocalAddress()
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress::GetLocalAddress());
|
return FromSFMLAddress(sf::IpAddress::GetLocalAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,16 +123,16 @@ sfIPAddress sfIPAddress_GetLocalAddress()
|
|||||||
/// distant website ; as a consequence, this function may be
|
/// distant website ; as a consequence, this function may be
|
||||||
/// very slow -- use it as few as possible !
|
/// very slow -- use it as few as possible !
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_GetPublicAddress(float timeout)
|
sfIpAddress sfIpAddress_GetPublicAddress(float timeout)
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress::GetPublicAddress(timeout));
|
return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's loopback address
|
/// Get the computer's loopback address
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfIPAddress sfIPAddress_LocalHost()
|
sfIpAddress sfIpAddress_LocalHost()
|
||||||
{
|
{
|
||||||
return FromSFMLAddress(sf::IPAddress::LocalHost);
|
return FromSFMLAddress(sf::IpAddress::LocalHost);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include <SFML/Network/SocketTCP.h>
|
#include <SFML/Network/SocketTCP.h>
|
||||||
#include <SFML/Network/SocketTCPStruct.h>
|
#include <SFML/Network/SocketTCPStruct.h>
|
||||||
#include <SFML/Network/PacketStruct.h>
|
#include <SFML/Network/PacketStruct.h>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -79,9 +79,9 @@ void sfSocketTCP_SetBlocking(sfSocketTCP* socket, sfBool blocking)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Connect a TCP socket to another computer on a specified port
|
/// Connect a TCP socket to another computer on a specified port
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIPAddress host, float timeout)
|
sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* socket, unsigned short port, sfIpAddress host, float timeout)
|
||||||
{
|
{
|
||||||
sf::IPAddress address(host.Address);
|
sf::IpAddress address(host.Address);
|
||||||
|
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError);
|
CSFML_CHECK_RETURN(socket, sfSocketError);
|
||||||
|
|
||||||
@ -103,13 +103,13 @@ sfBool sfSocketTCP_Listen(sfSocketTCP* socket, unsigned short port)
|
|||||||
/// This function is blocking, ie. it won't return before
|
/// This function is blocking, ie. it won't return before
|
||||||
/// a connection has been accepted
|
/// a connection has been accepted
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIPAddress* address)
|
sfSocketStatus sfSocketTCP_Accept(sfSocketTCP* socket, sfSocketTCP** connected, sfIpAddress* address)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError);
|
CSFML_CHECK_RETURN(socket, sfSocketError);
|
||||||
CSFML_CHECK_RETURN(connected, sfSocketError);
|
CSFML_CHECK_RETURN(connected, sfSocketError);
|
||||||
|
|
||||||
// Call SFML internal function
|
// Call SFML internal function
|
||||||
sf::IPAddress clientAddress;
|
sf::IpAddress clientAddress;
|
||||||
sf::SocketTCP client;
|
sf::SocketTCP client;
|
||||||
sf::Socket::Status status = socket->This.Accept(client, &clientAddress);
|
sf::Socket::Status status = socket->This.Accept(client, &clientAddress);
|
||||||
if (status != sf::Socket::Done)
|
if (status != sf::Socket::Done)
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include <SFML/Network/SocketUDP.h>
|
#include <SFML/Network/SocketUDP.h>
|
||||||
#include <SFML/Network/SocketUDPStruct.h>
|
#include <SFML/Network/SocketUDPStruct.h>
|
||||||
#include <SFML/Network/PacketStruct.h>
|
#include <SFML/Network/PacketStruct.h>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -97,12 +97,12 @@ sfBool sfSocketUDP_Unbind(sfSocketUDP* socket)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send an array of bytes
|
/// Send an array of bytes
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIPAddress address, unsigned short port)
|
sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t size, sfIpAddress address, unsigned short port)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError)
|
CSFML_CHECK_RETURN(socket, sfSocketError)
|
||||||
|
|
||||||
// Convert the address
|
// Convert the address
|
||||||
sf::IPAddress receiver(address.Address);
|
sf::IpAddress receiver(address.Address);
|
||||||
|
|
||||||
return static_cast<sfSocketStatus>(socket->This.Send(data, size, receiver, port));
|
return static_cast<sfSocketStatus>(socket->This.Send(data, size, receiver, port));
|
||||||
}
|
}
|
||||||
@ -113,12 +113,12 @@ sfSocketStatus sfSocketUDP_Send(sfSocketUDP* socket, const char* data, size_t si
|
|||||||
/// This function is blocking, ie. it won't return before some
|
/// This function is blocking, ie. it won't return before some
|
||||||
/// bytes have been received
|
/// bytes have been received
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIPAddress* address, unsigned short* port)
|
sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError);
|
CSFML_CHECK_RETURN(socket, sfSocketError);
|
||||||
|
|
||||||
// Call SFML internal function
|
// Call SFML internal function
|
||||||
sf::IPAddress sender;
|
sf::IpAddress sender;
|
||||||
unsigned short senderPort;
|
unsigned short senderPort;
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
|
|
||||||
@ -142,13 +142,13 @@ sfSocketStatus sfSocketUDP_Receive(sfSocketUDP* socket, char* data, size_t maxSi
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send a packet of data
|
/// Send a packet of data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress address, unsigned short port)
|
sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress address, unsigned short port)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError);
|
CSFML_CHECK_RETURN(socket, sfSocketError);
|
||||||
CSFML_CHECK_RETURN(packet, sfSocketError);
|
CSFML_CHECK_RETURN(packet, sfSocketError);
|
||||||
|
|
||||||
// Convert the address
|
// Convert the address
|
||||||
sf::IPAddress receiver(address.Address);
|
sf::IpAddress receiver(address.Address);
|
||||||
|
|
||||||
return static_cast<sfSocketStatus>(socket->This.Send(packet->This, receiver, port));
|
return static_cast<sfSocketStatus>(socket->This.Send(packet->This, receiver, port));
|
||||||
}
|
}
|
||||||
@ -159,12 +159,12 @@ sfSocketStatus sfSocketUDP_SendPacket(sfSocketUDP* socket, sfPacket* packet, sfI
|
|||||||
/// This function is blocking, ie. it won't return before a
|
/// This function is blocking, ie. it won't return before a
|
||||||
/// packet is received
|
/// packet is received
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIPAddress* address, unsigned short* port)
|
sfSocketStatus sfSocketUDP_ReceivePacket(sfSocketUDP* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(socket, sfSocketError);
|
CSFML_CHECK_RETURN(socket, sfSocketError);
|
||||||
CSFML_CHECK_RETURN(packet, sfSocketError);
|
CSFML_CHECK_RETURN(packet, sfSocketError);
|
||||||
|
|
||||||
sf::IPAddress sender;
|
sf::IpAddress sender;
|
||||||
unsigned short senderPort;
|
unsigned short senderPort;
|
||||||
sf::Socket::Status status = socket->This.Receive(packet->This, sender, senderPort);
|
sf::Socket::Status status = socket->This.Receive(packet->This, sender, senderPort);
|
||||||
if (status != sf::Socket::Done)
|
if (status != sf::Socket::Done)
|
||||||
|
@ -49,15 +49,15 @@ EXPORTS
|
|||||||
sfHttp_Destroy
|
sfHttp_Destroy
|
||||||
sfHttp_SetHost
|
sfHttp_SetHost
|
||||||
sfHttp_SendRequest
|
sfHttp_SendRequest
|
||||||
sfIPAddress_FromString
|
sfIpAddress_FromString
|
||||||
sfIPAddress_FromBytes
|
sfIpAddress_FromBytes
|
||||||
sfIPAddress_FromInteger
|
sfIpAddress_FromInteger
|
||||||
sfIPAddress_IsValid
|
sfIpAddress_IsValid
|
||||||
sfIPAddress_ToString
|
sfIpAddress_ToString
|
||||||
sfIPAddress_ToInteger
|
sfIpAddress_ToInteger
|
||||||
sfIPAddress_GetLocalAddress
|
sfIpAddress_GetLocalAddress
|
||||||
sfIPAddress_GetPublicAddress
|
sfIpAddress_GetPublicAddress
|
||||||
sfIPAddress_LocalHost
|
sfIpAddress_LocalHost
|
||||||
sfSocketTCP_Create
|
sfSocketTCP_Create
|
||||||
sfSocketTCP_Destroy
|
sfSocketTCP_Destroy
|
||||||
sfSocketTCP_SetBlocking
|
sfSocketTCP_SetBlocking
|
||||||
|
@ -49,15 +49,15 @@ EXPORTS
|
|||||||
sfHttp_Destroy
|
sfHttp_Destroy
|
||||||
sfHttp_SetHost
|
sfHttp_SetHost
|
||||||
sfHttp_SendRequest
|
sfHttp_SendRequest
|
||||||
sfIPAddress_FromString
|
sfIpAddress_FromString
|
||||||
sfIPAddress_FromBytes
|
sfIpAddress_FromBytes
|
||||||
sfIPAddress_FromInteger
|
sfIpAddress_FromInteger
|
||||||
sfIPAddress_IsValid
|
sfIpAddress_IsValid
|
||||||
sfIPAddress_ToString
|
sfIpAddress_ToString
|
||||||
sfIPAddress_ToInteger
|
sfIpAddress_ToInteger
|
||||||
sfIPAddress_GetLocalAddress
|
sfIpAddress_GetLocalAddress
|
||||||
sfIPAddress_GetPublicAddress
|
sfIpAddress_GetPublicAddress
|
||||||
sfIPAddress_LocalHost
|
sfIpAddress_LocalHost
|
||||||
sfSocketTCP_Create
|
sfSocketTCP_Create
|
||||||
sfSocketTCP_Copy
|
sfSocketTCP_Copy
|
||||||
sfSocketTCP_Destroy
|
sfSocketTCP_Destroy
|
||||||
|
@ -114,7 +114,7 @@
|
|||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\..\include\SFML\Network\Ftp.hpp" />
|
<Unit filename="..\..\include\SFML\Network\Ftp.hpp" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Http.hpp" />
|
<Unit filename="..\..\include\SFML\Network\Http.hpp" />
|
||||||
<Unit filename="..\..\include\SFML\Network\IPAddress.hpp" />
|
<Unit filename="..\..\include\SFML\Network\IpAddress.hpp" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Packet.hpp" />
|
<Unit filename="..\..\include\SFML\Network\Packet.hpp" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Selector.hpp" />
|
<Unit filename="..\..\include\SFML\Network\Selector.hpp" />
|
||||||
<Unit filename="..\..\include\SFML\Network\Selector.inl" />
|
<Unit filename="..\..\include\SFML\Network\Selector.inl" />
|
||||||
@ -125,7 +125,7 @@
|
|||||||
<Unit filename="..\..\include\SFML\Network\Win32\SocketHelper.hpp" />
|
<Unit filename="..\..\include\SFML\Network\Win32\SocketHelper.hpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Ftp.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Ftp.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Http.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Http.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\IPAddress.cpp" />
|
<Unit filename="..\..\src\SFML\Network\IpAddress.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\Packet.cpp" />
|
<Unit filename="..\..\src\SFML\Network\Packet.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\SelectorBase.cpp" />
|
<Unit filename="..\..\src\SFML\Network\SelectorBase.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Network\SocketTCP.cpp" />
|
<Unit filename="..\..\src\SFML\Network\SocketTCP.cpp" />
|
||||||
|
@ -369,11 +369,11 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Network\IPAddress.cpp"
|
RelativePath="..\..\src\SFML\Network\IpAddress.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\include\SFML\Network\IPAddress.hpp"
|
RelativePath="..\..\include\SFML\Network\IpAddress.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -368,11 +368,11 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Network\IPAddress.cpp"
|
RelativePath="..\..\src\SFML\Network\IpAddress.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\include\SFML\Network\IPAddress.hpp"
|
RelativePath="..\..\include\SFML\Network\IpAddress.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include <SFML/Network/Ftp.hpp>
|
#include <SFML/Network/Ftp.hpp>
|
||||||
#include <SFML/Network/Http.hpp>
|
#include <SFML/Network/Http.hpp>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/Packet.hpp>
|
#include <SFML/Network/Packet.hpp>
|
||||||
#include <SFML/Network/Selector.hpp>
|
#include <SFML/Network/Selector.hpp>
|
||||||
#include <SFML/Network/SocketTCP.hpp>
|
#include <SFML/Network/SocketTCP.hpp>
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class IPAddress;
|
class IpAddress;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// This class provides methods for manipulating the FTP
|
/// This class provides methods for manipulating the FTP
|
||||||
@ -267,7 +267,7 @@ public :
|
|||||||
/// \return Server response to the request
|
/// \return Server response to the request
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Response Connect(const IPAddress& server, unsigned short port = 21, float timeout = 0.f);
|
Response Connect(const IpAddress& server, unsigned short port = 21, float timeout = 0.f);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Log in using anonymous account
|
/// Log in using anonymous account
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/SocketTCP.hpp>
|
#include <SFML/Network/SocketTCP.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -334,7 +334,7 @@ private :
|
|||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketTCP myConnection; ///< Connection to the host
|
SocketTCP myConnection; ///< Connection to the host
|
||||||
IPAddress myHost; ///< Web host address
|
IpAddress myHost; ///< Web host address
|
||||||
std::string myHostName; ///< Web host name
|
std::string myHostName; ///< Web host name
|
||||||
unsigned short myPort; ///< Port used for connection with host
|
unsigned short myPort; ///< Port used for connection with host
|
||||||
};
|
};
|
||||||
|
@ -37,56 +37,93 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// IPAddress provides easy manipulation of IP v4 addresses
|
/// \brief Encapsulate an IPv4 network address
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_API IPAddress
|
class SFML_API IpAddress
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Default constructor -- constructs an invalid address
|
/// \brief Default constructor
|
||||||
|
///
|
||||||
|
/// This constructor creates an empty (invalid) address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IPAddress();
|
IpAddress();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a string
|
/// \brief Construct the address from a string
|
||||||
///
|
///
|
||||||
/// \param address : IP address ("xxx.xxx.xxx.xxx") or network name
|
/// Here \a address can be either a decimal address
|
||||||
|
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||||
|
///
|
||||||
|
/// \param address IP address or network name
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IPAddress(const std::string& address);
|
IpAddress(const std::string& address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a C-style string ;
|
/// \brief Construct the address from a string
|
||||||
/// Needed for implicit conversions from literal strings to IPAddress to work
|
|
||||||
///
|
///
|
||||||
/// \param address : IP address ("xxx.xxx.xxx.xxx") or network name
|
/// Here \a address can be either a decimal address
|
||||||
|
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||||
|
/// This is equivalent to the constructor taking a std::string
|
||||||
|
/// parameter, it is defined for convenience so that the
|
||||||
|
/// implicit conversions from literal strings to IpAddress work.
|
||||||
|
///
|
||||||
|
/// \param address IP address or network name
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IPAddress(const char* address);
|
IpAddress(const char* address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from 4 bytes
|
/// \brief Construct the address from 4 bytes
|
||||||
///
|
///
|
||||||
/// \param byte0 : First byte of the address
|
/// Calling IpAddress(a, b, c, d) is equivalent to calling
|
||||||
/// \param byte1 : Second byte of the address
|
/// IpAddress("a.b.c.d"), but safer as it doesn't have to
|
||||||
/// \param byte2 : Third byte of the address
|
/// parse a string to get the address components.
|
||||||
/// \param byte3 : Fourth byte of the address
|
///
|
||||||
|
/// \param byte0 First byte of the address
|
||||||
|
/// \param byte1 Second byte of the address
|
||||||
|
/// \param byte2 Third byte of the address
|
||||||
|
/// \param byte3 Fourth byte of the address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IPAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a 32-bits integer
|
/// \brief Construct the address from a 32-bits integer
|
||||||
///
|
///
|
||||||
/// \param address : 4 bytes of the address packed into a 32-bits integer
|
/// 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().
|
||||||
|
///
|
||||||
|
/// \param address 4 bytes of the address packed into a 32-bits integer
|
||||||
|
///
|
||||||
|
/// \see ToInteger
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IPAddress(Uint32 address);
|
IpAddress(Uint32 address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Tell if the address is a valid one
|
/// \brief Check if the address is a valid one
|
||||||
|
///
|
||||||
|
/// If the address was constructed from a decimal representation
|
||||||
|
/// (like "192.168.1.56") this function will always return true
|
||||||
|
/// unless the address is the special one 255.255.255.255.
|
||||||
|
/// If the address was constructed from a host name, it is
|
||||||
|
/// reported as beeing valid only if the host exists and could
|
||||||
|
/// be converted to a decimal IP address.
|
||||||
|
///
|
||||||
|
/// Examples:
|
||||||
|
/// \begincode
|
||||||
|
/// bool b1 = sf::IpAddress("127.0.0.1").IsValid(); // true
|
||||||
|
/// bool b2 = sf::IpAddress("1.2.3.4").IsValid(); // true
|
||||||
|
/// bool b3 = sf::IpAddress("www.google.com").IsValid(); // true
|
||||||
|
/// bool b4 = sf::IpAddress("www.dfgfghqsd.com").IsValid(); // false
|
||||||
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \return True if address has a valid syntax
|
/// \return True if address has a valid syntax
|
||||||
///
|
///
|
||||||
@ -94,46 +131,79 @@ public :
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a string representation of the address
|
/// \brief Get a string representation of the address
|
||||||
///
|
///
|
||||||
/// \return String representation of the IP address ("xxx.xxx.xxx.xxx")
|
/// The returned string is the decimal representation of the
|
||||||
|
/// IP address (like "192.168.1.56"), even if it was constructed
|
||||||
|
/// from a host name.
|
||||||
|
///
|
||||||
|
/// \return String representation of the address
|
||||||
|
///
|
||||||
|
/// \see ToInteger
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get an integer representation of the address
|
/// \brief Get an integer representation of the address
|
||||||
///
|
///
|
||||||
/// \return 32-bits integer containing the 4 bytes of the address, in system endianness
|
/// The returned number is the internal representation of the
|
||||||
|
/// address, and should be used for optimization purposes only
|
||||||
|
/// (like sending the address through a socket).
|
||||||
|
/// The integer produced by this function can then be converted
|
||||||
|
/// back to a sf::IpAddress with the proper constructor.
|
||||||
|
///
|
||||||
|
/// \return 32-bits unsigned integer representation of the address
|
||||||
|
///
|
||||||
|
/// \see ToString
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Uint32 ToInteger() const;
|
Uint32 ToInteger() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's local IP address (from the LAN point of view)
|
/// \brief Get the computer's local address
|
||||||
///
|
///
|
||||||
/// \return Local IP address
|
/// The local address is the address of the computer from the
|
||||||
|
/// LAN point of view, i.e. something like 192.168.1.56. It is
|
||||||
|
/// meaningful only for communications over the local network.
|
||||||
|
/// Unlike GetPublicAddress, this function is fast and may be
|
||||||
|
/// used safely anywhere.
|
||||||
|
///
|
||||||
|
/// \return Local IP address of the computer
|
||||||
|
///
|
||||||
|
/// \see GetPublicAddress
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static IPAddress GetLocalAddress();
|
static IpAddress GetLocalAddress();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's public IP address (from the web point of view).
|
/// \brief Get the computer's public address
|
||||||
|
///
|
||||||
|
/// The public address is the address of the computer from the
|
||||||
|
/// internet point of view, i.e. something like 89.54.1.169.
|
||||||
|
/// It is necessary for communications over the world wide web.
|
||||||
/// The only way to get a public address is to ask it to a
|
/// The only way to get a public address is to ask it to a
|
||||||
/// distant website ; as a consequence, this function may be
|
/// distant website; as a consequence, this function depends on
|
||||||
/// very slow -- use it as few as possible !
|
/// both your network connection and the server, and may be
|
||||||
|
/// very slow. You should use it as few as possible. Because
|
||||||
|
/// this function depends on the network connection and on a distant
|
||||||
|
/// server, you may use a time limit if you don't want your program
|
||||||
|
/// to be possibly stuck waiting in case there is a problem; this
|
||||||
|
/// limit is deactivated by default.
|
||||||
///
|
///
|
||||||
/// \param timeout : Maximum time to wait, in seconds (0 by default : no timeout)
|
/// \param timeout Maximum time to wait, in seconds
|
||||||
///
|
///
|
||||||
/// \return Public IP address
|
/// \return Public IP address of the computer
|
||||||
|
///
|
||||||
|
/// \see GetLocalAddress
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static IPAddress GetPublicAddress(float timeout = 0.f);
|
static IpAddress GetPublicAddress(float timeout = 0.f);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Static member data
|
// Static member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static const IPAddress LocalHost; ///< Local host address (to connect to the same computer)
|
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
@ -144,94 +214,121 @@ private :
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of == operator to compare two host addresses
|
/// \brief Overload of == operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if both hosts are equal
|
/// \return True if both addresses are equal
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator ==(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator ==(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of != operator to compare two host addresses
|
/// \brief Overload of != operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if both hosts are different
|
/// \return True if both addresses are different
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator !=(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator !=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of < operator to compare two host addresses
|
/// \brief Overload of < operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is lesser than \a right
|
/// \return True if \a left is lesser than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator <(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator <(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of > operator to compare two host addresses
|
/// \brief Overload of > operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is greater than \a right
|
/// \return True if \a left is greater than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator >(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator >(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of <= operator to compare two host addresses
|
/// \brief Overload of <= operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is lesser or equal than \a right
|
/// \return True if \a left is lesser or equal than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator <=(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator <=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of >= operator to compare two host addresses
|
/// \brief Overload of >= operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a host address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a host address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is greater or equal than \a right
|
/// \return True if \a left is greater or equal than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator >=(const IPAddress& left, const IPAddress& right);
|
SFML_API bool operator >=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Operator >> overload to extract an host address from an input stream
|
/// \brief Overload of >> operator to extract an IP address from an input stream
|
||||||
///
|
///
|
||||||
/// \param Stream : Input stream
|
/// \param stream Input stream
|
||||||
/// \param Address : Host address to extract
|
/// \param address IP address to extract
|
||||||
///
|
///
|
||||||
/// \return Reference to the input stream
|
/// \return Reference to the input stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API std::istream& operator >>(std::istream& stream, IPAddress& address);
|
SFML_API std::istream& operator >>(std::istream& stream, IpAddress& address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Operator << overload to print an host address to an output stream
|
/// \brief Overload of << operator to print an IP address to an output stream
|
||||||
///
|
///
|
||||||
/// \param Stream : Output stream
|
/// \param stream Output stream
|
||||||
/// \param Address : Host address to print
|
/// \param address IP address to print
|
||||||
///
|
///
|
||||||
/// \return Reference to the output stream
|
/// \return Reference to the output stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API std::ostream& operator <<(std::ostream& stream, const IPAddress& address);
|
SFML_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IPADDRESS_HPP
|
#endif // SFML_IPADDRESS_HPP
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \class sf::IpAddress
|
||||||
|
///
|
||||||
|
/// sf::IpAddress is a utility class for manipulating network
|
||||||
|
/// addresses. It provides a set a implicit constructors and
|
||||||
|
/// conversion functions to easily build or transform an IP
|
||||||
|
/// address from/to various representations.
|
||||||
|
///
|
||||||
|
/// Usage example:
|
||||||
|
/// \code
|
||||||
|
/// sf::IpAddress a1; // an invalid address
|
||||||
|
/// sf::IpAddress a2("127.0.0.1"); // the local host address
|
||||||
|
/// sf::IpAddress a3 = sf::IpAddress::LocalHost; // the local host address (same as a2)
|
||||||
|
/// sf::IpAddress a4(192, 168, 1, 56); // a local address
|
||||||
|
/// sf::IpAddress a5("my_computer"); // a local address created from a network name
|
||||||
|
/// sf::IpAddress a6("89.54.1.169"); // a distant address
|
||||||
|
/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name
|
||||||
|
/// sf::IpAddress a8 = sf::IpAddress::GetLocalAddress(); // my address on the local network
|
||||||
|
/// sf::IpAddress a9 = sf::IpAddress::GetPublicAddress(); // my address on the internet
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// Note that sf::IpAddress currently doesn't support IPv6
|
||||||
|
/// nor other types of network addresses.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Packet;
|
class Packet;
|
||||||
class IPAddress;
|
class IpAddress;
|
||||||
template <typename> class Selector;
|
template <typename> class Selector;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -71,7 +71,7 @@ public :
|
|||||||
/// \return True if operation has been successful
|
/// \return True if operation has been successful
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Connect(unsigned short port, const IPAddress& host, float timeout = 0.f);
|
Socket::Status Connect(unsigned short port, const IpAddress& host, float timeout = 0.f);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Listen to a specified port for incoming data or connections
|
/// Listen to a specified port for incoming data or connections
|
||||||
@ -93,7 +93,7 @@ public :
|
|||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Accept(SocketTCP& connected, IPAddress* address = NULL);
|
Socket::Status Accept(SocketTCP& connected, IpAddress* address = NULL);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send an array of bytes to the host (must be connected first)
|
/// Send an array of bytes to the host (must be connected first)
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Packet;
|
class Packet;
|
||||||
class IPAddress;
|
class IpAddress;
|
||||||
template <typename> class Selector;
|
template <typename> class Selector;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -90,7 +90,7 @@ public :
|
|||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Send(const char* data, std::size_t sizeInBytes, const IPAddress& address, unsigned short port);
|
Socket::Status Send(const char* data, std::size_t sizeInBytes, const IpAddress& address, unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Receive an array of bytes.
|
/// Receive an array of bytes.
|
||||||
@ -105,7 +105,7 @@ public :
|
|||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IPAddress& address, unsigned short& port);
|
Socket::Status Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IpAddress& address, unsigned short& port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send a packet of data
|
/// Send a packet of data
|
||||||
@ -117,7 +117,7 @@ public :
|
|||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Send(Packet& packet, const IPAddress& address, unsigned short port);
|
Socket::Status Send(Packet& packet, const IpAddress& address, unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Receive a packet.
|
/// Receive a packet.
|
||||||
@ -130,7 +130,7 @@ public :
|
|||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status Receive(Packet& packet, IPAddress& address, unsigned short& port);
|
Socket::Status Receive(Packet& packet, IpAddress& address, unsigned short& port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Close the socket
|
/// Close the socket
|
||||||
|
@ -26,7 +26,7 @@ std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& respons
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Choose the server address
|
// Choose the server address
|
||||||
sf::IPAddress address;
|
sf::IpAddress address;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Enter the FTP server address : ";
|
std::cout << "Enter the FTP server address : ";
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
void DoClientTCP(unsigned short port)
|
void DoClientTCP(unsigned short port)
|
||||||
{
|
{
|
||||||
// Ask for server address
|
// Ask for server address
|
||||||
sf::IPAddress serverAddress;
|
sf::IpAddress serverAddress;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type address or name of the server to connect to : ";
|
std::cout << "Type address or name of the server to connect to : ";
|
||||||
@ -66,7 +66,7 @@ void DoServerTCP(unsigned short port)
|
|||||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||||
|
|
||||||
// Wait for a connection
|
// Wait for a connection
|
||||||
sf::IPAddress clientAddress;
|
sf::IpAddress clientAddress;
|
||||||
sf::SocketTCP client;
|
sf::SocketTCP client;
|
||||||
if (server.Accept(client, &clientAddress) != sf::Socket::Done)
|
if (server.Accept(client, &clientAddress) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
|
@ -10,28 +10,28 @@
|
|||||||
/// Create a client and send a message to a running server
|
/// Create a client and send a message to a running server
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void DoClientUDP(unsigned short Port)
|
void DoClientUDP(unsigned short port)
|
||||||
{
|
{
|
||||||
// Ask for server address
|
// Ask for server address
|
||||||
sf::IPAddress ServerAddress;
|
sf::IpAddress serverAddress;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type address or name of the server to send the message to : ";
|
std::cout << "Type address or name of the server to send the message to : ";
|
||||||
std::cin >> ServerAddress;
|
std::cin >> serverAddress;
|
||||||
}
|
}
|
||||||
while (!ServerAddress.IsValid());
|
while (!serverAddress.IsValid());
|
||||||
|
|
||||||
// Create a UDP socket for communicating with server
|
// Create a UDP socket for communicating with server
|
||||||
sf::SocketUDP Client;
|
sf::SocketUDP client;
|
||||||
|
|
||||||
// Send a message to the server
|
// Send a message to the server
|
||||||
char Message[] = "Hi, I'm a client !";
|
char message[] = "Hi, I'm a client !";
|
||||||
if (Client.Send(Message, sizeof(Message), ServerAddress, Port) != sf::Socket::Done)
|
if (client.Send(message, sizeof(message), serverAddress, port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message sent to server : \"" << Message << "\"" << std::endl;
|
std::cout << "Message sent to server : \"" << message << "\"" << std::endl;
|
||||||
|
|
||||||
// Close the socket when we're done
|
// Close the socket when we're done
|
||||||
Client.Close();
|
client.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,27 +39,27 @@ void DoClientUDP(unsigned short Port)
|
|||||||
/// Launch a server and wait for incoming messages
|
/// Launch a server and wait for incoming messages
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void DoServerUDP(unsigned short Port)
|
void DoServerUDP(unsigned short port)
|
||||||
{
|
{
|
||||||
// Create a UDP socket for communicating with clients
|
// Create a UDP socket for communicating with clients
|
||||||
sf::SocketUDP Server;
|
sf::SocketUDP server;
|
||||||
|
|
||||||
// Bind it to the specified port
|
// Bind it to the specified port
|
||||||
if (!Server.Bind(Port))
|
if (!server.Bind(port))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Receive a message from anyone
|
// Receive a message from anyone
|
||||||
sf::IPAddress ClientAddress;
|
sf::IpAddress clientAddress;
|
||||||
unsigned short ClientPort;
|
unsigned short clientPort;
|
||||||
char Message[128];
|
char message[128];
|
||||||
std::size_t Received;
|
std::size_t received;
|
||||||
if (Server.Receive(Message, sizeof(Message), Received, ClientAddress, ClientPort) != sf::Socket::Done)
|
if (server.Receive(message, sizeof(message), received, clientAddress, clientPort) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Display it
|
// Display it
|
||||||
std::cout << "Message received from " << ClientAddress << " on port " << ClientPort
|
std::cout << "Message received from " << clientAddress << " on port " << clientPort
|
||||||
<< ": \"" << Message << "\"" << std::endl;
|
<< ": \"" << message << "\"" << std::endl;
|
||||||
|
|
||||||
// Close the socket when we're done
|
// Close the socket when we're done
|
||||||
Server.Close();
|
server.Close();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ void DoClient(unsigned short port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ask for server address
|
// Ask for server address
|
||||||
sf::IPAddress serverAddress;
|
sf::IpAddress serverAddress;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type address or name of the server to connect to : ";
|
std::cout << "Type address or name of the server to connect to : ";
|
||||||
|
@ -57,7 +57,7 @@ public :
|
|||||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||||
|
|
||||||
// Wait for a connection
|
// Wait for a connection
|
||||||
sf::IPAddress clientAddress;
|
sf::IpAddress clientAddress;
|
||||||
myListener.Accept(myClient, &clientAddress);
|
myListener.Accept(myClient, &clientAddress);
|
||||||
std::cout << "Client connected : " << clientAddress << std::endl;
|
std::cout << "Client connected : " << clientAddress << std::endl;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Ftp.hpp>
|
#include <SFML/Network/Ftp.hpp>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@ -192,7 +192,7 @@ Ftp::~Ftp()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Connect to the specified FTP server
|
/// Connect to the specified FTP server
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Ftp::Response Ftp::Connect(const IPAddress& server, unsigned short port, float timeout)
|
Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, float timeout)
|
||||||
{
|
{
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
if (myCommandSocket.Connect(port, server, timeout) != Socket::Done)
|
if (myCommandSocket.Connect(port, server, timeout) != Socket::Done)
|
||||||
@ -647,7 +647,7 @@ Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode)
|
|||||||
|
|
||||||
// Reconstruct connection port and address
|
// Reconstruct connection port and address
|
||||||
unsigned short port = data[4] * 256 + data[5];
|
unsigned short port = data[4] * 256 + data[5];
|
||||||
IPAddress address(static_cast<Uint8>(data[0]),
|
IpAddress address(static_cast<Uint8>(data[0]),
|
||||||
static_cast<Uint8>(data[1]),
|
static_cast<Uint8>(data[1]),
|
||||||
static_cast<Uint8>(data[2]),
|
static_cast<Uint8>(data[2]),
|
||||||
static_cast<Uint8>(data[3]));
|
static_cast<Uint8>(data[3]));
|
||||||
|
@ -350,7 +350,7 @@ void Http::SetHost(const std::string& host, unsigned short port)
|
|||||||
if (!myHostName.empty() && (*myHostName.rbegin() == '/'))
|
if (!myHostName.empty() && (*myHostName.rbegin() == '/'))
|
||||||
myHostName.erase(myHostName.size() - 1);
|
myHostName.erase(myHostName.size() - 1);
|
||||||
|
|
||||||
myHost = IPAddress(myHostName);
|
myHost = IpAddress(myHostName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/Http.hpp>
|
#include <SFML/Network/Http.hpp>
|
||||||
#include <SFML/Network/SocketHelper.hpp>
|
#include <SFML/Network/SocketHelper.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -34,15 +34,11 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Static member data
|
const IpAddress IpAddress::LocalHost(127, 0, 0, 1);
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const IPAddress IPAddress::LocalHost(127, 0, 0, 1);
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Default constructor
|
IpAddress::IpAddress() :
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress::IPAddress() :
|
|
||||||
myAddress(INADDR_NONE)
|
myAddress(INADDR_NONE)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -50,9 +46,7 @@ myAddress(INADDR_NONE)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a string
|
IpAddress::IpAddress(const std::string& address)
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress::IPAddress(const std::string& address)
|
|
||||||
{
|
{
|
||||||
// First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
|
// First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
|
||||||
myAddress = inet_addr(address.c_str());
|
myAddress = inet_addr(address.c_str());
|
||||||
@ -76,10 +70,7 @@ IPAddress::IPAddress(const std::string& address)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a C-style string ;
|
IpAddress::IpAddress(const char* address)
|
||||||
/// Needed for implicit conversions from literal strings to IPAddress to work
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress::IPAddress(const char* address)
|
|
||||||
{
|
{
|
||||||
// First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
|
// First try to convert it as a byte representation ("xxx.xxx.xxx.xxx")
|
||||||
myAddress = inet_addr(address);
|
myAddress = inet_addr(address);
|
||||||
@ -103,36 +94,28 @@ IPAddress::IPAddress(const char* address)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from 4 bytes
|
IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3)
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress::IPAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3)
|
|
||||||
{
|
{
|
||||||
myAddress = htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3);
|
myAddress = htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Construct the address from a 32-bits integer
|
IpAddress::IpAddress(Uint32 address)
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress::IPAddress(Uint32 address)
|
|
||||||
{
|
{
|
||||||
myAddress = htonl(address);
|
myAddress = htonl(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Tell if the address is a valid one
|
bool IpAddress::IsValid() const
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool IPAddress::IsValid() const
|
|
||||||
{
|
{
|
||||||
return myAddress != INADDR_NONE;
|
return myAddress != INADDR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a string representation of the address
|
std::string IpAddress::ToString() const
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::string IPAddress::ToString() const
|
|
||||||
{
|
{
|
||||||
in_addr address;
|
in_addr address;
|
||||||
address.s_addr = myAddress;
|
address.s_addr = myAddress;
|
||||||
@ -142,24 +125,20 @@ std::string IPAddress::ToString() const
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get an integer representation of the address
|
Uint32 IpAddress::ToInteger() const
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint32 IPAddress::ToInteger() const
|
|
||||||
{
|
{
|
||||||
return ntohl(myAddress);
|
return ntohl(myAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's local IP address (from the LAN point of view)
|
IpAddress IpAddress::GetLocalAddress()
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress IPAddress::GetLocalAddress()
|
|
||||||
{
|
{
|
||||||
// The method here is to connect a UDP socket to anyone (here to localhost),
|
// The method here is to connect a UDP socket to anyone (here to localhost),
|
||||||
// and get the local socket address with the getsockname function.
|
// and get the local socket address with the getsockname function.
|
||||||
// UDP connection will not send anything to the network, so this function won't cause any overhead.
|
// UDP connection will not send anything to the network, so this function won't cause any overhead.
|
||||||
|
|
||||||
IPAddress localAddress;
|
IpAddress localAddress;
|
||||||
|
|
||||||
// Create the socket
|
// Create the socket
|
||||||
SocketHelper::SocketType sock = socket(PF_INET, SOCK_DGRAM, 0);
|
SocketHelper::SocketType sock = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
@ -199,82 +178,80 @@ IPAddress IPAddress::GetLocalAddress()
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the computer's public IP address (from the web point of view)
|
IpAddress IpAddress::GetPublicAddress(float timeout)
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IPAddress IPAddress::GetPublicAddress(float timeout)
|
|
||||||
{
|
{
|
||||||
// The trick here is more complicated, because the only way
|
// The trick here is more complicated, because the only way
|
||||||
// to get our public IP address is to get it from a distant computer.
|
// to get our public IP address is to get it from a distant computer.
|
||||||
// Here we get the web page from http://www.sfml-dev.org/ip-provider.php
|
// Here we get the web page from http://www.sfml-dev.org/ip-provider.php
|
||||||
// and parse the result to extract our IP address
|
// and parse the result to extract our IP address
|
||||||
// (not very hard : the web page contains only our IP address).
|
// (not very hard: the web page contains only our IP address).
|
||||||
|
|
||||||
Http server("www.sfml-dev.org");
|
Http server("www.sfml-dev.org");
|
||||||
Http::Request request(Http::Request::Get, "/ip-provider.php");
|
Http::Request request(Http::Request::Get, "/ip-provider.php");
|
||||||
Http::Response page = server.SendRequest(request, timeout);
|
Http::Response page = server.SendRequest(request, timeout);
|
||||||
if (page.GetStatus() == Http::Response::Ok)
|
if (page.GetStatus() == Http::Response::Ok)
|
||||||
return IPAddress(page.GetBody());
|
return IpAddress(page.GetBody());
|
||||||
|
|
||||||
// Something failed: return an invalid address
|
// Something failed: return an invalid address
|
||||||
return IPAddress();
|
return IpAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator ==(const IPAddress& left, const IPAddress& right)
|
bool operator ==(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return left.ToInteger() == right.ToInteger();
|
return left.ToInteger() == right.ToInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator !=(const IPAddress& left, const IPAddress& right)
|
bool operator !=(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator <(const IPAddress& left, const IPAddress& right)
|
bool operator <(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return left.ToInteger() < right.ToInteger();
|
return left.ToInteger() < right.ToInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator >(const IPAddress& left, const IPAddress& right)
|
bool operator >(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return right < left;
|
return right < left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator <=(const IPAddress& left, const IPAddress& right)
|
bool operator <=(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return !(right < left);
|
return !(right < left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator >=(const IPAddress& left, const IPAddress& right)
|
bool operator >=(const IpAddress& left, const IpAddress& right)
|
||||||
{
|
{
|
||||||
return !(left < right);
|
return !(left < right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::istream& operator >>(std::istream& stream, IPAddress& address)
|
std::istream& operator >>(std::istream& stream, IpAddress& address)
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
stream >> str;
|
stream >> str;
|
||||||
address = IPAddress(str);
|
address = IpAddress(str);
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::ostream& operator <<(std::ostream& stream, const IPAddress& address)
|
std::ostream& operator <<(std::ostream& stream, const IpAddress& address)
|
||||||
{
|
{
|
||||||
return stream << address.ToString();
|
return stream << address.ToString();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/SocketTCP.hpp>
|
#include <SFML/Network/SocketTCP.hpp>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/Packet.hpp>
|
#include <SFML/Network/Packet.hpp>
|
||||||
#include <SFML/Network/SocketHelper.hpp>
|
#include <SFML/Network/SocketHelper.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
@ -67,7 +67,7 @@ void SocketTCP::SetBlocking(bool blocking)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Connect to another computer on a specified port
|
/// Connect to another computer on a specified port
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketTCP::Connect(unsigned short port, const IPAddress& host, float timeout)
|
Socket::Status SocketTCP::Connect(unsigned short port, const IpAddress& host, float timeout)
|
||||||
{
|
{
|
||||||
// Make sure our socket is valid
|
// Make sure our socket is valid
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
@ -203,7 +203,7 @@ bool SocketTCP::Listen(unsigned short port)
|
|||||||
/// Wait for a connection (must be listening to a port).
|
/// Wait for a connection (must be listening to a port).
|
||||||
/// This function will block if the socket is blocking
|
/// This function will block if the socket is blocking
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketTCP::Accept(SocketTCP& connected, IPAddress* address)
|
Socket::Status SocketTCP::Accept(SocketTCP& connected, IpAddress* address)
|
||||||
{
|
{
|
||||||
// Address that will be filled with client informations
|
// Address that will be filled with client informations
|
||||||
sockaddr_in clientAddress;
|
sockaddr_in clientAddress;
|
||||||
@ -216,14 +216,14 @@ Socket::Status SocketTCP::Accept(SocketTCP& connected, IPAddress* address)
|
|||||||
if (!connected.IsValid())
|
if (!connected.IsValid())
|
||||||
{
|
{
|
||||||
if (address)
|
if (address)
|
||||||
*address = IPAddress();
|
*address = IpAddress();
|
||||||
|
|
||||||
return SocketHelper::GetErrorStatus();
|
return SocketHelper::GetErrorStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill address if requested
|
// Fill address if requested
|
||||||
if (address)
|
if (address)
|
||||||
*address = IPAddress(inet_ntoa(clientAddress.sin_addr));
|
*address = IpAddress(inet_ntoa(clientAddress.sin_addr));
|
||||||
|
|
||||||
return Socket::Done;
|
return Socket::Done;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/SocketUDP.hpp>
|
#include <SFML/Network/SocketUDP.hpp>
|
||||||
#include <SFML/Network/IPAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/Packet.hpp>
|
#include <SFML/Network/Packet.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -115,7 +115,7 @@ bool SocketUDP::Unbind()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send an array of bytes
|
/// Send an array of bytes
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const IPAddress& address, unsigned short port)
|
Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const IpAddress& address, unsigned short port)
|
||||||
{
|
{
|
||||||
// Make sure the socket is valid
|
// Make sure the socket is valid
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
@ -159,7 +159,7 @@ Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const
|
|||||||
/// Receive an array of bytes.
|
/// Receive an array of bytes.
|
||||||
/// This function will block if the socket is blocking
|
/// This function will block if the socket is blocking
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IPAddress& address, unsigned short& port)
|
Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& sizeReceived, IpAddress& address, unsigned short& port)
|
||||||
{
|
{
|
||||||
// First clear the size received
|
// First clear the size received
|
||||||
sizeReceived = 0;
|
sizeReceived = 0;
|
||||||
@ -192,14 +192,14 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t&
|
|||||||
// Check the number of bytes received
|
// Check the number of bytes received
|
||||||
if (received > 0)
|
if (received > 0)
|
||||||
{
|
{
|
||||||
address = IPAddress(inet_ntoa(sockAddr.sin_addr));
|
address = IpAddress(inet_ntoa(sockAddr.sin_addr));
|
||||||
port = ntohs(sockAddr.sin_port);
|
port = ntohs(sockAddr.sin_port);
|
||||||
sizeReceived = static_cast<std::size_t>(received);
|
sizeReceived = static_cast<std::size_t>(received);
|
||||||
return Socket::Done;
|
return Socket::Done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
address = IPAddress();
|
address = IpAddress();
|
||||||
port = 0;
|
port = 0;
|
||||||
return received == 0 ? Socket::Disconnected : SocketHelper::GetErrorStatus();
|
return received == 0 ? Socket::Disconnected : SocketHelper::GetErrorStatus();
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t&
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send a packet of data
|
/// Send a packet of data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketUDP::Send(Packet& packet, const IPAddress& address, unsigned short port)
|
Socket::Status SocketUDP::Send(Packet& packet, const IpAddress& address, unsigned short port)
|
||||||
{
|
{
|
||||||
// Get the data to send from the packet
|
// Get the data to send from the packet
|
||||||
std::size_t dataSize = 0;
|
std::size_t dataSize = 0;
|
||||||
@ -242,7 +242,7 @@ Socket::Status SocketUDP::Send(Packet& packet, const IPAddress& address, unsigne
|
|||||||
/// Receive a packet.
|
/// Receive a packet.
|
||||||
/// This function will block if the socket is blocking
|
/// This function will block if the socket is blocking
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned short& port)
|
Socket::Status SocketUDP::Receive(Packet& packet, IpAddress& address, unsigned short& port)
|
||||||
{
|
{
|
||||||
// We start by getting the size of the incoming packet
|
// We start by getting the size of the incoming packet
|
||||||
Uint32 packetSize = 0;
|
Uint32 packetSize = 0;
|
||||||
@ -272,7 +272,7 @@ Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned s
|
|||||||
|
|
||||||
// Use another address instance for receiving the packet data ;
|
// Use another address instance for receiving the packet data ;
|
||||||
// chunks of data coming from a different sender will be discarded (and lost...)
|
// chunks of data coming from a different sender will be discarded (and lost...)
|
||||||
IPAddress sender;
|
IpAddress sender;
|
||||||
unsigned short senderPort;
|
unsigned short senderPort;
|
||||||
|
|
||||||
// Then loop until we receive all the packet data
|
// Then loop until we receive all the packet data
|
||||||
|
@ -34,8 +34,6 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::size_t String::InvalidPos = std::basic_string<Uint32>::npos;
|
const std::size_t String::InvalidPos = std::basic_string<Uint32>::npos;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user