@@ -52,7 +52,7 @@ namespace kt
5252 * @throw SocketException - If the ServerSocket is unable to be instanciated or begin listening.
5353 * @throw BindingException - If the ServerSocket is unable to bind to the specific port specified.
5454 */
55- kt::ServerSocket::ServerSocket (const kt::SocketType type, const unsigned short & port, const unsigned int & connectionBacklogSize, const kt::InternetProtocolVersion protocolVersion)
55+ kt::ServerSocket::ServerSocket (const kt::SocketType type, const std::optional<std::string>& localHostname, const unsigned short & port, const unsigned int & connectionBacklogSize, const kt::InternetProtocolVersion protocolVersion)
5656 {
5757 this ->socketDescriptor = getInvalidSocketValue ();
5858 this ->port = port;
@@ -64,7 +64,7 @@ namespace kt
6464 throw SocketException (" Failed to create ServerSocket with 'None' SocketType." );
6565 }
6666
67- this ->constructSocket (connectionBacklogSize);
67+ this ->constructSocket (localHostname, connectionBacklogSize);
6868 }
6969
7070 /* *
@@ -99,11 +99,11 @@ namespace kt
9999 return *this ;
100100 }
101101
102- void kt::ServerSocket::constructSocket (const unsigned int & connectionBacklogSize)
102+ void kt::ServerSocket::constructSocket (const std::optional<std::string>& localHostname, const unsigned int & connectionBacklogSize)
103103 {
104104 if (this ->type == kt::SocketType::Wifi)
105105 {
106- this ->constructWifiSocket (connectionBacklogSize);
106+ this ->constructWifiSocket (localHostname, connectionBacklogSize);
107107 }
108108 else if (this ->type == kt::SocketType::Bluetooth)
109109 {
@@ -170,7 +170,7 @@ namespace kt
170170
171171 }
172172
173- void kt::ServerSocket::constructWifiSocket (const unsigned int & connectionBacklogSize)
173+ void kt::ServerSocket::constructWifiSocket (const std::optional<std::string>& localHostname, const unsigned int & connectionBacklogSize)
174174 {
175175
176176#ifdef _WIN32
@@ -182,7 +182,7 @@ namespace kt
182182#endif
183183
184184 addrinfo hints = kt::createTcpHints (this ->protocolVersion , AI_PASSIVE);
185- std::pair<std::vector<kt::SocketAddress>, int > resolveAddresses = kt::resolveToAddresses (kt::getLocalAddress (protocolVersion), this ->port , hints);
185+ std::pair<std::vector<kt::SocketAddress>, int > resolveAddresses = kt::resolveToAddresses (localHostname. has_value () ? localHostname. value (). c_str () : kt::getLocalAddress (protocolVersion), this ->port , hints);
186186
187187 if (resolveAddresses.second != 0 || resolveAddresses.first .empty ())
188188 {
0 commit comments