refactoring on Server detection
This commit is contained in:
@@ -1,39 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class SAD_DetectedServer;
|
|
||||||
class I_SAD_Client {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* If a new server was found by the ServerAutoDetect mechanism, this function is called.<br>
|
|
||||||
* To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.<br>
|
|
||||||
* If a server can be reached via several IP addresses, the IP address is selected according to the following preference:<br>
|
|
||||||
* 1.) If a loopback address is available, it is used.<br>
|
|
||||||
* 2.) If an IP4 address is available, it is used.<br>
|
|
||||||
* 3.) In the other cases the IP6 address is used.<br>
|
|
||||||
* @param p_ID the id of the server (every started server should generate an id)
|
|
||||||
* @param p_Name the name of the SPIT server
|
|
||||||
* @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running
|
|
||||||
* @param p_IP the selected ip address of the SPIT server
|
|
||||||
* @param p_Port the port of the SPIT server
|
|
||||||
* @param p_Addition sometimes server may have additional informations
|
|
||||||
* @param p_IsIP4 the server ip is a ip4 address
|
|
||||||
*/
|
|
||||||
virtual void eventServerDetected(SAD_DetectedServer &server) = 0;
|
|
||||||
/**
|
|
||||||
* If a SPITServer is not more found, this function is called.
|
|
||||||
* To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.<br>
|
|
||||||
* @param p_ID the id of the server (every started server should generate an id)
|
|
||||||
* @param p_Name the name of the SPIT server
|
|
||||||
* @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running
|
|
||||||
* @param p_IP the selected ip address of the SPIT server
|
|
||||||
* @param p_Port the port of the SPIT server
|
|
||||||
* @param p_Addition sometimes server may have additional informations
|
|
||||||
* @param p_IsIP4 the server ip is a ip4 address
|
|
||||||
*/
|
|
||||||
virtual void eventServerChanged(SAD_DetectedServer &server) = 0;
|
|
||||||
|
|
||||||
virtual void eventServerLost(SAD_DetectedServer &server) = 0;
|
|
||||||
};
|
|
||||||
@@ -1,36 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "I_SAD_Client.hpp"
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class SAD_DetectedServer {
|
class SAD_DetectedServer;
|
||||||
|
class I_SAD_Client {
|
||||||
public:
|
public:
|
||||||
SAD_DetectedServer();
|
virtual void eventServerDetected(SAD_DetectedServer &server) = 0;
|
||||||
SAD_DetectedServer(const SAD_DetectedServer &orig) {
|
virtual void eventServerChanged(SAD_DetectedServer &server) = 0;
|
||||||
m_ID = orig.getID();
|
virtual void eventServerLost(SAD_DetectedServer &server) = 0;
|
||||||
m_Name = orig.getName();
|
};
|
||||||
m_ComputerName = orig.getComputerName();
|
|
||||||
m_IP = orig.getIP();
|
class SAD_DetectedServer {
|
||||||
m_ClientIP = orig.getClientIP();
|
public:
|
||||||
m_Port = orig.getPort();
|
SAD_DetectedServer() {}
|
||||||
m_Additions = orig.getAdditions();
|
SAD_DetectedServer(const SAD_DetectedServer &orig)
|
||||||
|
: m_ID(orig.m_ID),
|
||||||
|
m_Name(orig.m_Name),
|
||||||
|
m_ComputerName(orig.m_ComputerName),
|
||||||
|
m_IP(orig.m_IP),
|
||||||
|
m_ClientIP(orig.m_ClientIP),
|
||||||
|
m_Port(orig.m_Port),
|
||||||
|
m_Additions(orig.m_Additions) {
|
||||||
}
|
}
|
||||||
~SAD_DetectedServer();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_ID;
|
string m_ID{};
|
||||||
string m_Name;
|
string m_Name{};
|
||||||
string m_ComputerName;
|
string m_ComputerName{};
|
||||||
string m_IP;
|
string m_IP{};
|
||||||
string m_ClientIP;
|
string m_ClientIP{};
|
||||||
string m_Port;
|
string m_Port{};
|
||||||
string m_Additions;
|
string m_Additions{};
|
||||||
string m_ServerProjectName;
|
string m_ServerProjectName{};
|
||||||
bool m_New;
|
bool m_New;
|
||||||
bool m_Changed;
|
bool m_Changed;
|
||||||
bool m_FoundAgain;
|
bool m_FoundAgain;
|
||||||
@@ -46,14 +51,14 @@ class SAD_DetectedServer {
|
|||||||
string getProjectName() const { return m_ServerProjectName; }
|
string getProjectName() const { return m_ServerProjectName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setID(string p_ID) { m_ID = p_ID; }
|
void setID(const string& p_ID) { m_ID = p_ID; }
|
||||||
void setName(string p_Name) { m_Name = p_Name; }
|
void setName(const string& p_Name) { m_Name = p_Name; }
|
||||||
void setComputerName(string p_ComputerName) { m_ComputerName = p_ComputerName; }
|
void setComputerName(const string& p_ComputerName) { m_ComputerName = p_ComputerName; }
|
||||||
void setIP(string p_IP) { m_IP = p_IP; }
|
void setIP(const string& p_IP) { m_IP = p_IP; }
|
||||||
void setClientIP(string p_IP) { m_ClientIP = p_IP; }
|
void setClientIP(const string& p_IP) { m_ClientIP = p_IP; }
|
||||||
void setPort(string p_Port) { m_Port = p_Port; }
|
void setPort(const string& p_Port) { m_Port = p_Port; }
|
||||||
void setAdditions(string p_Additions) { m_Additions = p_Additions; }
|
void setAdditions(const string& p_Additions) { m_Additions = p_Additions; }
|
||||||
void setProjectName(string p_ServerProjectName);
|
void setProjectName(const string& projName);
|
||||||
|
|
||||||
bool getNew() const { return m_New; }
|
bool getNew() const { return m_New; }
|
||||||
bool getChanged() const { return m_Changed; }
|
bool getChanged() const { return m_Changed; }
|
||||||
@@ -63,7 +68,7 @@ class SAD_DetectedServer {
|
|||||||
void setFoundAgain() { m_FoundAgain = true; }
|
void setFoundAgain() { m_FoundAgain = true; }
|
||||||
|
|
||||||
// SAD_Client m_ThreadSend will send to Multicast addresses
|
// SAD_Client m_ThreadSend will send to Multicast addresses
|
||||||
void startCycleSAD() {
|
void resetFlags() {
|
||||||
m_Changed = false;
|
m_Changed = false;
|
||||||
m_FoundAgain = false;
|
m_FoundAgain = false;
|
||||||
m_New = false;
|
m_New = false;
|
||||||
@@ -83,21 +88,8 @@ class SAD_DetectedServer {
|
|||||||
static const int PARAMINDEX_ADDITIONS = 7;
|
static const int PARAMINDEX_ADDITIONS = 7;
|
||||||
static const int PARAMINDEX_SERVERPROJECTNAME = 8;
|
static const int PARAMINDEX_SERVERPROJECTNAME = 8;
|
||||||
static const int PARAMINDEX_IP = 9;
|
static const int PARAMINDEX_IP = 9;
|
||||||
/**
|
static void addDetectedServer(string &id, string p_ServerParams[]);
|
||||||
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
|
||||||
* @param p_IsIP4 true = the server is reached via a IP4 address<br>false = the server is reahed via a IP6 address
|
|
||||||
* @param p_ServerID the id of the server, every instance of a SPITServer has an own id
|
|
||||||
* @param p_ServerParams the server's parameter
|
|
||||||
*/
|
|
||||||
static void addDetectedServer(string p_ServerID, string p_ServerParams[]);
|
|
||||||
/**
|
|
||||||
* Used by SAD_Client to remove a SPITServer - don't use this manually
|
|
||||||
* @param p_DetectedServer
|
|
||||||
*/
|
|
||||||
static void removeDetectedServer(SAD_DetectedServer &server);
|
static void removeDetectedServer(SAD_DetectedServer &server);
|
||||||
/**
|
|
||||||
* Used by SAD_Client to clear all found SPITServers - don't use this manually
|
|
||||||
*/
|
|
||||||
static void clearDetectedServers();
|
static void clearDetectedServers();
|
||||||
/**
|
/**
|
||||||
* Used by SAD_Client internally - don't use this manually
|
* Used by SAD_Client internally - don't use this manually
|
||||||
@@ -115,5 +107,5 @@ class SAD_DetectedServer {
|
|||||||
* @param p_ServerID the id of the SPITServer
|
* @param p_ServerID the id of the SPITServer
|
||||||
* @return the reference of the SAD_DetectedServer instance with getID() == p_ServerID
|
* @return the reference of the SAD_DetectedServer instance with getID() == p_ServerID
|
||||||
*/
|
*/
|
||||||
static const SAD_DetectedServer &getRefDetectedServer(string p_ServerID);
|
static const SAD_DetectedServer &getRefDetectedServer(const string &id);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ class SPITSocket {
|
|||||||
m_ClientIP = "";
|
m_ClientIP = "";
|
||||||
m_ClientPort = "";
|
m_ClientPort = "";
|
||||||
m_BoundClientPort = "";
|
m_BoundClientPort = "";
|
||||||
m_BoundClientFamily = 0;
|
|
||||||
m_IsBound = false;
|
m_IsBound = false;
|
||||||
createSocket_UDP();
|
createSocket_UDP();
|
||||||
}
|
}
|
||||||
@@ -107,60 +106,52 @@ class SPITSocket {
|
|||||||
string m_ClientIP;
|
string m_ClientIP;
|
||||||
string m_ClientPort; // port given by the user maybe "0"
|
string m_ClientPort; // port given by the user maybe "0"
|
||||||
string m_BoundClientPort; // port set after bind
|
string m_BoundClientPort; // port set after bind
|
||||||
int m_BoundClientFamily;
|
|
||||||
bool m_IsBound;
|
bool m_IsBound;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
// Sets the ip address and port for server and client.
|
||||||
* Sets the ip address and port for server and client.
|
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) {
|
||||||
* @param p_ServerIP
|
m_ServerIP = serverIp;
|
||||||
* @param p_ServerPort
|
m_ServerPort = serverPort;
|
||||||
* @param p_ClientIP
|
m_ClientIP = clientIp;
|
||||||
* @param p_ClientPort
|
m_ClientPort = clientPort;
|
||||||
*/
|
|
||||||
void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort) {
|
|
||||||
m_ServerIP = p_ServerIP;
|
|
||||||
m_ServerPort = p_ServerPort;
|
|
||||||
m_ClientIP = p_ClientIP;
|
|
||||||
m_ClientPort = p_ClientPort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the server as set by setConnectionParams
|
* Send a message to the server as set by setConnectionParams
|
||||||
* @param p_MessageBytes byte buffer containing the message
|
* @param message byte buffer containing the message
|
||||||
* @param p_MessageLength length of the messaeg
|
* @param length length of the message
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int sendMessage(const char *p_MessageBytes, int p_MessageLength) {
|
int sendMessage(const char *message, int length) {
|
||||||
if (m_ServerPort.length() <= 0)
|
if (m_ServerPort.length() <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
int intResult;
|
int intResult;
|
||||||
{
|
{
|
||||||
if (m_IsBound == false)
|
if (m_IsBound == false)
|
||||||
return -1;
|
return -1;
|
||||||
intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength);
|
intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
|
||||||
}
|
}
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
int receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP);
|
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
|
||||||
int setBroadcast(bool p_Broadcast);
|
int setBroadcast(bool p_Broadcast) const;
|
||||||
int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort);
|
int bindSocket(string clientIp, string clientPort);
|
||||||
|
|
||||||
// * Internal usage - don't use this manually
|
int sendMessageTo(const string& ip, const string&port, const char *message, int msgLength);
|
||||||
// * Use sendMessage instead
|
|
||||||
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char *p_MessageBytes, int p_MessageLength);
|
|
||||||
|
|
||||||
string getServerIP() { return m_ServerIP; }
|
string getServerIP() const { return m_ServerIP; }
|
||||||
string getServerPort() { return m_ServerPort; }
|
string getServerPort() const { return m_ServerPort; }
|
||||||
string getClientIP() { return m_ClientIP; }
|
string getClientIP() const { return m_ClientIP; }
|
||||||
string getClientPort() { return m_ClientPort; }
|
string getClientPort() const { return m_ClientPort; }
|
||||||
string getBoundClientPort() { return m_BoundClientPort; }
|
string getBoundClientPort() const { return m_BoundClientPort; }
|
||||||
void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; }
|
void setBoundClientPort(const string &p_Port) { m_BoundClientPort = p_Port; }
|
||||||
void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; }
|
|
||||||
int getBoundClientFamily() { return m_BoundClientFamily; }
|
|
||||||
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
|
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
|
||||||
bool getIsBound() { return m_IsBound; }
|
bool getIsBound() const { return m_IsBound; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPITSOCKET_H */
|
#endif /* SPITSOCKET_H */
|
||||||
|
|||||||
@@ -19,32 +19,19 @@ static const char *TAG = "SpitSrv";
|
|||||||
|
|
||||||
unordered_map<string, SAD_DetectedServer *> SAD_DetectedServer::s_DetectedServers;
|
unordered_map<string, SAD_DetectedServer *> SAD_DetectedServer::s_DetectedServers;
|
||||||
|
|
||||||
SAD_DetectedServer::~SAD_DetectedServer() {
|
void SAD_DetectedServer::setProjectName(const string& projName) {
|
||||||
}
|
if ((m_ServerProjectName.compare(projName) != 0) && (m_New == false)) {
|
||||||
//----- Detected Server -----
|
m_Changed = true;
|
||||||
SAD_DetectedServer::SAD_DetectedServer() {
|
|
||||||
m_ID = "";
|
|
||||||
m_Name = "";
|
|
||||||
m_ComputerName = "";
|
|
||||||
m_ClientIP = "";
|
|
||||||
m_Port = "";
|
|
||||||
m_Additions = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void SAD_DetectedServer::setProjectName(string p_ServerProjectName) {
|
|
||||||
if (m_ServerProjectName.compare(p_ServerProjectName) != 0) {
|
|
||||||
if (m_New == false) {
|
|
||||||
m_Changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_ServerProjectName = p_ServerProjectName;
|
m_ServerProjectName = projName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAD_DetectedServer::cycleStart() {
|
void SAD_DetectedServer::cycleStart() {
|
||||||
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
|
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
|
||||||
i->second->startCycleSAD();
|
i->second->resetFlags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAD_DetectedServer::cycleEnd(I_SAD_Client &sadClient) {
|
void SAD_DetectedServer::cycleEnd(I_SAD_Client &sadClient) {
|
||||||
for (auto &srv : s_DetectedServers) {
|
for (auto &srv : s_DetectedServers) {
|
||||||
SAD_DetectedServer *ptrDetectedServer = srv.second;
|
SAD_DetectedServer *ptrDetectedServer = srv.second;
|
||||||
@@ -62,33 +49,31 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client &sadClient) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
||||||
* @param p_IsIP4 true = the server is reached via a IP4 address<br>false = the server is reahed via a IP6 address
|
* @param id the id of the server, every instance of a SPITServer has an own id
|
||||||
* @param p_ServerID the id of the server, every instance of a SPITServer has an own id
|
|
||||||
* @param p_ServerParams the server's parameter
|
* @param p_ServerParams the server's parameter
|
||||||
*/
|
*/
|
||||||
void SAD_DetectedServer::addDetectedServer(string p_ServerID, string p_ServerParams[]) {
|
void SAD_DetectedServer::addDetectedServer(string &id, string p_ServerParams[]) {
|
||||||
SAD_DetectedServer *ptrDetectedServer;
|
SAD_DetectedServer *detectedServer;
|
||||||
{
|
{
|
||||||
auto i = s_DetectedServers.find(p_ServerID);
|
auto i = s_DetectedServers.find(id);
|
||||||
if (i != s_DetectedServers.end()) {
|
if (i != s_DetectedServers.end()) {
|
||||||
ptrDetectedServer = i->second;
|
detectedServer = i->second;
|
||||||
|
detectedServer->setFoundAgain();
|
||||||
} else {
|
} else {
|
||||||
ptrDetectedServer = new SAD_DetectedServer();
|
detectedServer = new SAD_DetectedServer();
|
||||||
ptrDetectedServer->setID(p_ServerParams[PARAMINDEX_ID]);
|
detectedServer->setID(p_ServerParams[PARAMINDEX_ID]);
|
||||||
ptrDetectedServer->setNew(true);
|
detectedServer->setNew(true);
|
||||||
}
|
}
|
||||||
ptrDetectedServer->setFoundAgain();
|
|
||||||
|
|
||||||
// second prefer IP4
|
detectedServer->setIP(p_ServerParams[PARAMINDEX_IP]);
|
||||||
ptrDetectedServer->setIP(p_ServerParams[PARAMINDEX_IP]);
|
detectedServer->setClientIP(p_ServerParams[PARAMINDEX_CLIENTIP]);
|
||||||
ptrDetectedServer->setClientIP(p_ServerParams[PARAMINDEX_CLIENTIP]);
|
detectedServer->setName(p_ServerParams[PARAMINDEX_NAME]);
|
||||||
ptrDetectedServer->setName(p_ServerParams[PARAMINDEX_NAME]);
|
detectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]);
|
||||||
ptrDetectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]);
|
detectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]);
|
||||||
ptrDetectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]);
|
detectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]);
|
||||||
ptrDetectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]);
|
detectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]);
|
||||||
ptrDetectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]);
|
|
||||||
|
|
||||||
s_DetectedServers[ptrDetectedServer->getID()] = ptrDetectedServer;
|
s_DetectedServers[detectedServer->getID()] = detectedServer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -112,22 +97,9 @@ void SAD_DetectedServer::clearDetectedServers() {
|
|||||||
SAD_DetectedServer *ptrDetectedServer = i->second;
|
SAD_DetectedServer *ptrDetectedServer = i->second;
|
||||||
i = s_DetectedServers.erase(i);
|
i = s_DetectedServers.erase(i);
|
||||||
delete ptrDetectedServer;
|
delete ptrDetectedServer;
|
||||||
if (i == s_DetectedServers.end()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAD_DetectedServer &SAD_DetectedServer::getRefDetectedServer(string p_ServerID) {
|
const SAD_DetectedServer &SAD_DetectedServer::getRefDetectedServer(const string &id) {
|
||||||
SAD_DetectedServer *ptrDetectedServer = nullptr;
|
return *s_DetectedServers.at(id);
|
||||||
|
|
||||||
auto i = s_DetectedServers.find(p_ServerID);
|
|
||||||
if (i != s_DetectedServers.end()) {
|
|
||||||
ptrDetectedServer = i->second;
|
|
||||||
}
|
|
||||||
if (ptrDetectedServer != NULL) {
|
|
||||||
return *ptrDetectedServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new exception();
|
|
||||||
}
|
}
|
||||||
@@ -27,27 +27,25 @@ using namespace std;
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool SPITSocket::createSocket_UDP() {
|
bool SPITSocket::createSocket_UDP() {
|
||||||
bool boolSuccess = true;
|
|
||||||
int intResult = -1;
|
|
||||||
int intOptionValue4 = 1;
|
|
||||||
|
|
||||||
// ip4
|
|
||||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
||||||
close(m_UDPSocketIP4);
|
close(m_UDPSocketIP4);
|
||||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
m_UDPSocketIP4 = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_UDPSocketIP4 = socket(AF_INET, SOCK_DGRAM, 0);
|
m_UDPSocketIP4 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
int intResult = -1;
|
||||||
|
bool success = true;
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
||||||
boolSuccess = false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
|
int intOptionValue4 = 1;
|
||||||
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
|
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
|
||||||
}
|
}
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
boolSuccess = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boolSuccess == true) {
|
if (success == true) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 1; // seconds
|
tv.tv_sec = 1; // seconds
|
||||||
tv.tv_usec = 0; // microseconds (0.0 sec)
|
tv.tv_usec = 0; // microseconds (0.0 sec)
|
||||||
@@ -64,138 +62,99 @@ bool SPITSocket::createSocket_UDP() {
|
|||||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||||
}
|
}
|
||||||
return boolSuccess;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds the socket to the client's ip address and port. The socket option SO_REUSEADDR is set to true.
|
* Binds the socket to the client's ip address and port. The socket option SO_REUSEADDR is set to true.
|
||||||
* @param p_ClientIP ip address of the client
|
* @param clientIp ip address of the client
|
||||||
* @param p_ClientPort port of the client.
|
* @param clientPort port of the client.
|
||||||
* if p_Port == "0" any free port will be used
|
* if p_Port == "0" any free port will be used
|
||||||
* @return -1 id bind fails, o if bind is ok
|
* @return -1 id bind fails, o if bind is ok
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int SPITSocket::bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort) {
|
int SPITSocket::bindSocket(string clientIp, string clientPort) {
|
||||||
addrinfo *clientAI;
|
|
||||||
struct sockaddr_in *ptrIP4SocketAddress;
|
|
||||||
struct sockaddr_in o_IP4SocketAddress;
|
|
||||||
int intSocklen;
|
|
||||||
string stringClientPort;
|
string stringClientPort;
|
||||||
if (p_ClientPort.length() <= 0)
|
if (clientPort.length() <= 0)
|
||||||
stringClientPort = "0";
|
stringClientPort = "0";
|
||||||
else
|
else
|
||||||
stringClientPort = p_ClientPort;
|
stringClientPort = clientPort;
|
||||||
// int intResult = SOCKET_ERROR;
|
addrinfo *clientAI;
|
||||||
int intResult = 0;
|
if (getaddrinfo(clientIp.data(), clientPort.data(), nullptr, &clientAI) != 0) {
|
||||||
if (getaddrinfo(p_ClientIP.data(), p_ClientPort.data(), NULL, &clientAI) != 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
switch (clientAI->ai_family) {
|
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
||||||
case AF_INET:
|
return -1;
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
}
|
||||||
break;
|
auto *socketAdr = (sockaddr_in *)(clientAI->ai_addr);
|
||||||
}
|
int intSocklen = sizeof(*socketAdr);
|
||||||
ptrIP4SocketAddress = reinterpret_cast<sockaddr_in *>(clientAI->ai_addr);
|
// copy the socketAdr, may be not filled correct by getaddrinfo
|
||||||
intSocklen = sizeof(*ptrIP4SocketAddress);
|
sockaddr_in o_IP4SocketAddress;
|
||||||
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
|
memset(&o_IP4SocketAddress, 0, intSocklen);
|
||||||
memset(&o_IP4SocketAddress, 0, intSocklen);
|
o_IP4SocketAddress.sin_addr = socketAdr->sin_addr;
|
||||||
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
|
o_IP4SocketAddress.sin_family = socketAdr->sin_family;
|
||||||
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
|
o_IP4SocketAddress.sin_port = socketAdr->sin_port;
|
||||||
// o_IP4SocketAddress.sin_zero = ptrIP4SocketAddress->sin_zero;
|
int intResult = bind(m_UDPSocketIP4, (const sockaddr *)(socketAdr), (socklen_t)intSocklen);
|
||||||
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
|
if (intResult < 0) {
|
||||||
intResult = bind(m_UDPSocketIP4, (const sockaddr *)(ptrIP4SocketAddress), (socklen_t)intSocklen);
|
return intResult;
|
||||||
if (intResult < 0) {
|
}
|
||||||
break;
|
if ((intResult == 0) &&
|
||||||
}
|
(getsockname(m_UDPSocketIP4, (sockaddr *)socketAdr, (socklen_t *)&intSocklen) != -1)) {
|
||||||
setBoundClientFamily(AF_INET);
|
setBoundClientPort(to_string((int)socketAdr->sin_port));
|
||||||
if (intResult == 0) {
|
|
||||||
if (getsockname(m_UDPSocketIP4, (sockaddr *)ptrIP4SocketAddress, (socklen_t *)&intSocklen) != -1) {
|
|
||||||
setBoundClientPort(to_string((int)ptrIP4SocketAddress->sin_port));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
setBoundClientFamily(0);
|
|
||||||
intResult = -1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
freeaddrinfo(clientAI);
|
freeaddrinfo(clientAI);
|
||||||
|
|
||||||
if (intResult == -1) {
|
setIsBound(intResult != -1);
|
||||||
setIsBound(false);
|
|
||||||
} else {
|
|
||||||
setIsBound(true);
|
|
||||||
}
|
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the sockat are brodcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1
|
* Set whether the socket are broadcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1
|
||||||
* @param p_Broadcast true SO_BROADCAST is set
|
* @param p_Broadcast true SO_BROADCAST is set
|
||||||
* false = SO_BROADCAST is not set
|
* false = SO_BROADCAST is not set
|
||||||
* @return 0 = ok, -1 = error
|
* @return 0 = ok, -1 = error
|
||||||
*/
|
*/
|
||||||
int SPITSocket::setBroadcast(bool p_Broadcast) {
|
int SPITSocket::setBroadcast(bool broadcast) const {
|
||||||
int intResult;
|
int intOptionValue = broadcast ? 1 : 0;
|
||||||
int intOptionValue = 1;
|
int intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
|
||||||
u_char charOptionValue = 0x01;
|
|
||||||
// IP4
|
|
||||||
if (p_Broadcast) {
|
|
||||||
intOptionValue = 1;
|
|
||||||
} else {
|
|
||||||
intOptionValue = 0;
|
|
||||||
}
|
|
||||||
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
|
|
||||||
// intResult = setsockopt(m_UDPSocketIP4, IPPROTO_IP, IP_MULTICAST_LOOP, (void*)&charOptionValue, sizeof(charOptionValue));
|
|
||||||
|
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
* @param ip the ip address of the server
|
||||||
* @param p_InetFamily AF_INET or AF_INET6
|
* @param port the port of the server
|
||||||
* @param p_ServerIP the ip address of the server
|
* @param msg buffer containing the message
|
||||||
* @param p_ServerPort the port of the server
|
* @param msgLength the length of the message
|
||||||
* @param p_MessageBytes buffer containing the message
|
|
||||||
* @param p_MessageLength the length of the message
|
|
||||||
* @return -1 send fails
|
* @return -1 send fails
|
||||||
* 0 send is done
|
* 0 send is done
|
||||||
*/
|
*/
|
||||||
int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_ServerPort, const char *p_MessageBytes, int p_MessageLength) {
|
int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) {
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET)
|
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
||||||
return -1;
|
return -1;
|
||||||
struct addrinfo *ptrAddressInfo;
|
}
|
||||||
struct sockaddr_in *ptrIP4SocketAddress;
|
|
||||||
struct sockaddr_in o_IP4SocketAddress;
|
|
||||||
int intSocklen;
|
|
||||||
int intResult = -1;
|
|
||||||
|
|
||||||
// prepare AddressInfo
|
// prepare AddressInfo
|
||||||
if (getaddrinfo(p_ServerIP.data(), p_ServerPort.data(), NULL, &ptrAddressInfo) != 0) {
|
int intResult = -1;
|
||||||
return -1;
|
addrinfo *ptrAddressInfo;
|
||||||
}
|
if (getaddrinfo(ip.data(), port.data(), nullptr, &ptrAddressInfo) != 0) {
|
||||||
switch (ptrAddressInfo->ai_family) {
|
return intResult;
|
||||||
case AF_INET:
|
|
||||||
ptrIP4SocketAddress = reinterpret_cast<sockaddr_in *>(ptrAddressInfo->ai_addr);
|
|
||||||
intSocklen = sizeof(*ptrIP4SocketAddress);
|
|
||||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
|
||||||
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
|
|
||||||
memset(&o_IP4SocketAddress, 0, intSocklen);
|
|
||||||
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
|
|
||||||
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
|
|
||||||
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
|
|
||||||
intResult = sendto(m_UDPSocketIP4, p_MessageBytes, p_MessageLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
|
|
||||||
if (intResult < 0) {
|
|
||||||
printf("UnixSocket::sendMessageTo IP4 sendto %s FAILED %s\n", p_ServerIP.data(), strerror(errno));
|
|
||||||
printf("UnixSocket::sendMessageTo ret=%d %s / %s / %d\n", intResult,
|
|
||||||
p_ServerPort.data(), p_MessageBytes, p_MessageLength);
|
|
||||||
}
|
|
||||||
freeaddrinfo(ptrAddressInfo);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
intResult = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto *ptrIP4SocketAddress = (sockaddr_in *)(ptrAddressInfo->ai_addr);
|
||||||
|
int intSocklen = sizeof(*ptrIP4SocketAddress);
|
||||||
|
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
||||||
|
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
|
||||||
|
sockaddr_in o_IP4SocketAddress;
|
||||||
|
memset(&o_IP4SocketAddress, 0, intSocklen);
|
||||||
|
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
|
||||||
|
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
|
||||||
|
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
|
||||||
|
intResult = sendto(m_UDPSocketIP4, message, msgLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
|
||||||
|
if (intResult < 0) {
|
||||||
|
ESP_LOGE("SPIT", "sendMessageTo IP4 sendto %s FAILED %s\n", ip.data(), strerror(errno));
|
||||||
|
ESP_LOGE("SPIT", "sendMessageTo ret=%d %s / %s / %d\n", intResult, port.data(), message, msgLength);
|
||||||
|
}
|
||||||
|
freeaddrinfo(ptrAddressInfo);
|
||||||
|
}
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -204,52 +163,39 @@ int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Serv
|
|||||||
/**
|
/**
|
||||||
* Call this for receiving a message
|
* Call this for receiving a message
|
||||||
* This will block until a message is received or the underlying socket is closed
|
* This will block until a message is received or the underlying socket is closed
|
||||||
* @param p_InetFamily either AF_INET or AF_INET6<br>
|
|
||||||
* The SPITSocket creates two udp sockets, one for IP4 and one for IP6
|
|
||||||
* This parameter decides from which socket should a message recieved
|
|
||||||
* @param p_Buffer the buffer containing the received message later.
|
* @param p_Buffer the buffer containing the received message later.
|
||||||
* @param p_BufferLength the size of the buffer
|
* @param p_BufferLength the size of the buffer
|
||||||
* @param p_ServerIP a pointer to a string, when a messages is received the string will contain the ip address of the sender/server
|
* @param p_ServerIP a pointer to a string, when a messages is received the string will contain the ip address of the sender/server
|
||||||
* if p_ServerIP is NULL - no detection of the server will be done.
|
* if p_ServerIP is NULL - no detection of the server will be done.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int SPITSocket::receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP) {
|
int SPITSocket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const {
|
||||||
int intResult = -1;
|
int intResult = -1;
|
||||||
// ADDRINFO *AI;
|
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
||||||
struct sockaddr_in o_IP4SocketAddress;
|
return intResult;
|
||||||
int intSocklen;
|
}
|
||||||
|
sockaddr_in o_IP4SocketAddress;
|
||||||
switch (p_InetFamily) {
|
int intSocklen = sizeof(o_IP4SocketAddress);
|
||||||
case AF_INET:
|
memset(&o_IP4SocketAddress, 0, intSocklen);
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
|
||||||
break;
|
if (intResult >= 0 && serverIp != nullptr) {
|
||||||
}
|
char bufferIP4[INET_ADDRSTRLEN];
|
||||||
intSocklen = sizeof(o_IP4SocketAddress);
|
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
|
||||||
memset(&o_IP4SocketAddress, 0, intSocklen);
|
*serverIp = bufferIP4;
|
||||||
intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
|
|
||||||
if (intResult >= 0) {
|
|
||||||
if (p_ServerIP != NULL) {
|
|
||||||
char bufferIP4[INET_ADDRSTRLEN];
|
|
||||||
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
|
|
||||||
*p_ServerIP = bufferIP4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
|
SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
|
||||||
// iterate over active interfaces, and print out IPs
|
// iterate over active interfaces, and print out IPs
|
||||||
esp_netif_t *netif = NULL;
|
esp_netif_t *netif = nullptr;
|
||||||
while ((netif = esp_netif_next_unsafe(netif)) != NULL) {
|
if ((netif = esp_netif_next_unsafe(netif)) != nullptr) {
|
||||||
ESP_LOGI("SPIT", "Connected to %s", esp_netif_get_desc(netif));
|
ESP_LOGI("SPIT", "Connected to %s", esp_netif_get_desc(netif));
|
||||||
esp_netif_ip_info_t ip;
|
esp_netif_ip_info_t ip;
|
||||||
ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip));
|
ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip));
|
||||||
ESP_LOGI("SPIT", "- IPv4 address: " IPSTR ",", IP2STR(&ip.ip));
|
ESP_LOGI("SPIT", "- IPv4 address: " IPSTR ",", IP2STR(&ip.ip));
|
||||||
ESP_LOGI("SPIT", "- IPv4 netmask: " IPSTR ",", IP2STR(&ip.netmask));
|
ESP_LOGI("SPIT", "- IPv4 netmask: " IPSTR ",", IP2STR(&ip.netmask));
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
|
|
||||||
sprintf(buffer, IPSTR, IP2STR(&ip.ip));
|
sprintf(buffer, IPSTR, IP2STR(&ip.ip));
|
||||||
string stringIP4 = buffer;
|
string stringIP4 = buffer;
|
||||||
sprintf(buffer, IPSTR, IP2STR(&ip.netmask));
|
sprintf(buffer, IPSTR, IP2STR(&ip.netmask));
|
||||||
@@ -260,29 +206,18 @@ SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string createGUID() {
|
string createGUID() {
|
||||||
// uuid_t id;
|
|
||||||
// uuid_generate(id);
|
|
||||||
// char *guid_string = new char[100];
|
|
||||||
// uuid_unparse(id, guid_string);
|
|
||||||
// string stringGUID = guid_string;
|
|
||||||
// return stringGUID;
|
|
||||||
|
|
||||||
uuid_t uu;
|
uuid_t uu;
|
||||||
char uu_str[UUID_STR_LEN];
|
|
||||||
|
|
||||||
uuid_generate(uu);
|
uuid_generate(uu);
|
||||||
|
char uu_str[UUID_STR_LEN];
|
||||||
uuid_unparse(uu, uu_str);
|
uuid_unparse(uu, uu_str);
|
||||||
string stringGUID = uu_str;
|
return {uu_str};
|
||||||
return stringGUID;
|
|
||||||
}
|
}
|
||||||
/** The name of the client's host computer*/
|
|
||||||
string getClientHostName() {
|
string getClientHostName() {
|
||||||
string stringHostName = "";
|
|
||||||
const char *hostname;
|
const char *hostname;
|
||||||
esp_netif_get_hostname(esp_netif_get_default_netif(), &hostname);
|
esp_netif_get_hostname(esp_netif_get_default_netif(), &hostname);
|
||||||
if (hostname != nullptr) {
|
if (hostname != nullptr) {
|
||||||
stringHostName = hostname;
|
return {hostname};
|
||||||
}
|
}
|
||||||
return stringHostName;
|
return "";
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart &spitMessageOPPart) {
|
|||||||
}
|
}
|
||||||
bool SPIT_Client::startReceiveSPITMessages() {
|
bool SPIT_Client::startReceiveSPITMessages() {
|
||||||
{
|
{
|
||||||
if (mSPITSocket->getBoundClientFamily() <= 0)
|
if (!mSPITSocket->getIsBound())
|
||||||
return false;
|
return false;
|
||||||
m_StopReceiveSPITMessages = false;
|
m_StopReceiveSPITMessages = false;
|
||||||
m_ThreadReceive = new fos::TaskT<SPIT_Client &>(receiveSPITMessage, *this, "receiveTask", fos::Task::DefaultStackSize * 4);
|
m_ThreadReceive = new fos::TaskT<SPIT_Client &>(receiveSPITMessage, *this, "receiveTask", fos::Task::DefaultStackSize * 4);
|
||||||
@@ -317,7 +317,7 @@ void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
|||||||
if (rM.m_StopReceiveSPITMessages == true) {
|
if (rM.m_StopReceiveSPITMessages == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
intResult = rM.mSPITSocket->receiveMessage(rM.mSPITSocket->getBoundClientFamily(), buffer, MAXSPITMESSAGEBYTECOUNT, NULL);
|
intResult = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr);
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
if (rM.m_StopReceiveSPITMessages) {
|
if (rM.m_StopReceiveSPITMessages) {
|
||||||
return;
|
return;
|
||||||
@@ -534,7 +534,7 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
|
|||||||
disconnect();
|
disconnect();
|
||||||
{
|
{
|
||||||
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
|
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
|
||||||
intResult = mSPITSocket->bindSocket(p_ServerIP, p_ClientIP, p_ClientPort);
|
intResult = mSPITSocket->bindSocket(p_ClientIP, p_ClientPort);
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
m_StopReceiveSPITMessages = true;
|
m_StopReceiveSPITMessages = true;
|
||||||
return false;
|
return false;
|
||||||
@@ -1518,7 +1518,7 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
|||||||
|
|
||||||
SAD_DetectedServer::cycleStart();
|
SAD_DetectedServer::cycleStart();
|
||||||
string stringBroadcastIP4 = instance.mSPITSocket->mOwnIp.getBroadcastIP4();
|
string stringBroadcastIP4 = instance.mSPITSocket->mOwnIp.getBroadcastIP4();
|
||||||
instance.mSPITSocket->sendMessageTo(SPITSocket::FAMILY_IP4, stringBroadcastIP4, SERVERAUTODETECT_PORT, stringDatagram.data(), intDatagramLength);
|
instance.mSPITSocket->sendMessageTo(stringBroadcastIP4, SERVERAUTODETECT_PORT, stringDatagram.data(), intDatagramLength);
|
||||||
{
|
{
|
||||||
// wait for 3000 milliseconds or
|
// wait for 3000 milliseconds or
|
||||||
fos::Task::delayMs(3000);
|
fos::Task::delayMs(3000);
|
||||||
@@ -1531,7 +1531,7 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
|||||||
|
|
||||||
char buffer[512 + 1];
|
char buffer[512 + 1];
|
||||||
string stringServerIP;
|
string stringServerIP;
|
||||||
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(SPITSocket::FAMILY_IP4, buffer, 512, &stringServerIP);
|
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, 512, &stringServerIP);
|
||||||
if (intReceivedByteCount <= 0) {
|
if (intReceivedByteCount <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user