class IoTSocketServer final : public IoTSocket
{
- public:
+ public:
IoTSocketServer(int iPort, bool* pResult);
-
- bool connect(); // Accept a new connection
+ bool connect(); // Accept a new connection
protected:
- bool m_bReverse; // Am I reversing byte order or not?
- int m_iListen; // Descriptor we are listening on
- struct sockaddr_in m_addrMe; // My address information
+ bool m_bReverse; // Am I reversing byte order or not?
+ int m_iListen; // Descriptor we are listening on
+ struct sockaddr_in m_addrMe; // My address information
};
IoTSocket(iPort, pResult) {
m_iListen = -1;
-
if (pResult)
*pResult = false;
-
if ((m_iListen = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("IoTSocketServer: Socket error!");
bool IoTSocketServer::connect()
{
socklen_t iSinSize = (socklen_t) sizeof(struct sockaddr_in);
-
if ((m_iSock = accept(m_iListen, (struct sockaddr *) &m_addrRemote, &iSinSize)) == -1)
{
perror("IoTSocketServer: Accept connection error!");
return false;
}
+
// The client sends us an int to indicate if we should
// be reversing byte order on this connection. The client
// is sending 0 or 1, so a reversed 0 still looks
iResult = recv(m_iSock, temp, 1, 0);
iTotal += iResult;
}
+
if (iResult == -1)
{
perror("IoTSocketServer: Receive data error!");
}
int iVal = temp[0];
-
if (iVal == 0)
m_bReverse = false;
else
m_bReverse = true;
-
+
return true;
}