Added examples for a simple WebSocket client and Server.

Removed automatic ping pong response, and disconnection from fr::WebSocket, as it should be handled by the library user, really.

Updated ReadMe.
This commit is contained in:
Unknown
2018-03-03 16:02:17 +00:00
parent fa843b57c8
commit 13f709aebb
8 changed files with 24 additions and 52 deletions
+6 -5
View File
@@ -51,11 +51,6 @@ namespace fr
*/
Socket::Status receive_raw(void *data, size_t data_size, size_t &received) override;
/*!
* Close the connection.
*/
void close_socket() override;
/*!
* Connects the socket to an address.
*
@@ -126,6 +121,12 @@ namespace fr
private:
/*!
* Close the connection.
*/
void close_socket() override;
std::shared_ptr<SSLContext> ssl_context;
std::unique_ptr<mbedtls_net_context> ssl_socket_descriptor;
std::unique_ptr<mbedtls_ssl_context> ssl;
+6 -5
View File
@@ -21,11 +21,6 @@ public:
void operator=(TcpSocket &&)=delete;
void operator=(const TcpSocket &)=delete;
/*!
* Close the connection.
*/
virtual void close_socket();
/*!
* Connects the socket to an address.
*
@@ -99,6 +94,12 @@ public:
}
protected:
/*!
* Close the connection.
*/
virtual void close_socket();
int32_t socket_descriptor;
};
-39
View File
@@ -128,45 +128,6 @@ namespace fr
SocketType::send(response);
}
/*!
* Receive a Sendable object through the socket.
* Internally sends back a pong if a ping is received.
*
* @param obj The object to receive
* @return The status of the receive
*/
Socket::Status receive(Sendable &obj) override
{
WebFrame &frame = dynamic_cast<WebFrame&>(obj);
//Try and receive a message. If it's a ping, then silently send back a pong.
Socket::Status status;
while(true)
{
status = SocketType::receive(obj);
if(status != Socket::Success)
return status;
if(frame.get_opcode() == WebFrame::Ping)
{
frame.set_opcode(WebFrame::Pong);
status = SocketType::send(frame);
if(status != fr::Socket::Success)
return status;
continue;
}
break;
}
//If it's a disconnect
if(frame.get_opcode() == WebFrame::Disconnect)
{
disconnect();
return Socket::Disconnected;
}
return status;
}
/*!
* Checks to see if the socket initialised the connection, or
* if it was accepted by a listener.