}
/* create the primary JSON-RPC listener */
- if (!AddListener(GetBindPort())) {
- Log(LogCritical, "ApiListener", "Cannot add listener for port '" + Convert::ToString(GetBindPort()) + "'.");
+ if (!AddListener(GetBindHost(), GetBindPort())) {
+ Log(LogCritical, "ApiListener", "Cannot add listener on host '" + GetBindHost() + "' for port '" + GetBindPort() + "'.");
Application::Exit(EXIT_FAILURE);
}
/**
* Creates a new JSON-RPC listener on the specified port.
*
+ * @param node The host the listener should be bound to.
* @param service The port to listen on.
*/
-bool ApiListener::AddListener(const String& service)
+bool ApiListener::AddListener(const String& node, const String& service)
{
ObjectLock olock(this);
TcpSocket::Ptr server = make_shared<TcpSocket>();
try {
- server->Bind(service, AF_UNSPEC);
- } catch(std::exception&) {
- Log(LogCritical, "ApiListener", "Cannot bind tcp socket on '" + service + "'.");
+ server->Bind(node, service, AF_UNSPEC);
+ } catch (const std::exception&) {
+ Log(LogCritical, "ApiListener", "Cannot bind TCP socket for host '" + node + "' on port '" + service + "'.");
return false;
}
void ApiTimerHandler(void);
- bool AddListener(const String& service);
+ bool AddListener(const String& node, const String& service);
void AddConnection(const Endpoint::Ptr& endpoint);
void NewClientHandler(const Socket::Ptr& client, ConnectionRole role);