refactoring on Server detection
This commit is contained in:
@@ -85,7 +85,6 @@ class SPITSocket {
|
||||
m_ClientIP = "";
|
||||
m_ClientPort = "";
|
||||
m_BoundClientPort = "";
|
||||
m_BoundClientFamily = 0;
|
||||
m_IsBound = false;
|
||||
createSocket_UDP();
|
||||
}
|
||||
@@ -107,60 +106,52 @@ class SPITSocket {
|
||||
string m_ClientIP;
|
||||
string m_ClientPort; // port given by the user maybe "0"
|
||||
string m_BoundClientPort; // port set after bind
|
||||
int m_BoundClientFamily;
|
||||
bool m_IsBound;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Sets the ip address and port for server and client.
|
||||
* @param p_ServerIP
|
||||
* @param p_ServerPort
|
||||
* @param p_ClientIP
|
||||
* @param p_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;
|
||||
// Sets the ip address and port for server and client.
|
||||
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) {
|
||||
m_ServerIP = serverIp;
|
||||
m_ServerPort = serverPort;
|
||||
m_ClientIP = clientIp;
|
||||
m_ClientPort = clientPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the server as set by setConnectionParams
|
||||
* @param p_MessageBytes byte buffer containing the message
|
||||
* @param p_MessageLength length of the messaeg
|
||||
* @param message byte buffer containing the message
|
||||
* @param length length of the message
|
||||
* @return
|
||||
*/
|
||||
int sendMessage(const char *p_MessageBytes, int p_MessageLength) {
|
||||
int sendMessage(const char *message, int length) {
|
||||
if (m_ServerPort.length() <= 0)
|
||||
return -1;
|
||||
int intResult;
|
||||
{
|
||||
if (m_IsBound == false)
|
||||
return -1;
|
||||
intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength);
|
||||
intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
|
||||
}
|
||||
return intResult;
|
||||
}
|
||||
|
||||
int receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP);
|
||||
int setBroadcast(bool p_Broadcast);
|
||||
int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort);
|
||||
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
|
||||
int setBroadcast(bool p_Broadcast) const;
|
||||
int bindSocket(string clientIp, string clientPort);
|
||||
|
||||
// * Internal usage - don't use this manually
|
||||
// * Use sendMessage instead
|
||||
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char *p_MessageBytes, int p_MessageLength);
|
||||
int sendMessageTo(const string& ip, const string&port, const char *message, int msgLength);
|
||||
|
||||
string getServerIP() { return m_ServerIP; }
|
||||
string getServerPort() { return m_ServerPort; }
|
||||
string getClientIP() { return m_ClientIP; }
|
||||
string getClientPort() { return m_ClientPort; }
|
||||
string getBoundClientPort() { return m_BoundClientPort; }
|
||||
void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; }
|
||||
void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; }
|
||||
int getBoundClientFamily() { return m_BoundClientFamily; }
|
||||
string getServerIP() const { return m_ServerIP; }
|
||||
string getServerPort() const { return m_ServerPort; }
|
||||
string getClientIP() const { return m_ClientIP; }
|
||||
string getClientPort() const { return m_ClientPort; }
|
||||
string getBoundClientPort() const { return m_BoundClientPort; }
|
||||
void setBoundClientPort(const string &p_Port) { m_BoundClientPort = p_Port; }
|
||||
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
|
||||
bool getIsBound() { return m_IsBound; }
|
||||
bool getIsBound() const { return m_IsBound; }
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* SPITSOCKET_H */
|
||||
|
||||
Reference in New Issue
Block a user