Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

\begin{frame}[fragile]{\texttt{SocketContext} of the Server}
\begin{cppcode}[autogobble=true, caption={\alert{SocketContext} of the server.},captionpos=b]
#include <SemanticLog.h>

class EchoServerContext : public core::socket::stream::SocketContext {
public:
using core::socket::stream::SocketContext::SocketContext; // constructor inheritance (since C++11)

private:
void onConnected() override {
VLOG(0) << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString();
snode::semantic::appLog().trace() << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString();
}

void onDisconnected() override {
VLOG(0) << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString();
snode::semantic::appLog().trace() << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString();
}

std::size_t onReceivedFromPeer() override {
char junk[4096];

std::size_t junkLen = readFromPeer(junk, 4096);
if (junkLen > 0) {
VLOG(0) << "Data to reflect: " << std::string(junk, junkLen);
snode::semantic::appLog().trace() << "Data to reflect: " << std::string(junk, junkLen);
sendToPeer(junk, junkLen);
}
return junkLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

\begin{frame}[fragile]{\texttt{SocketContext} of the Client}
\begin{cppcode}[autogobble=true, caption={\alert{SocketContext} of the client.},captionpos=b]
#include <SemanticLog.h>

class EchoClientContext : public core::socket::stream::SocketContext {
public:
using core::socket::stream::SocketContext::SocketContext; // constructor inheritance (since C++11)

private:
void onConnected() override {.
VLOG(0) << "Echo connected to " << socketConnection->getRemoteAddress().toString();
VLOG(0) << "Initiating data exchange";
snode::semantic::appLog().trace() << "Echo connected to " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().trace() << "Initiating data exchange";
sendToPeer("Hello peer! It's nice talking to you!!!");
}

void onDisconnected() override {
VLOG(0) << "Echo disconnected from " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().trace() << "Echo disconnected from " << socketConnection->getRemoteAddress().toString();
}

std::size_t onReceivedFromPeer() override {
char junk[4096];

std::size_t junkLen = readFromPeer(junk, 4096);
if (junkLen > 0) {
VLOG(0) << "Data to reflect: " << std::string(junk, junkLen);
snode::semantic::appLog().trace() << "Data to reflect: " << std::string(junk, junkLen);
sendToPeer(junk, junkLen);
}
return junkLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
\begin{frame}[fragile]{The IPv4 Server Application}
\begin{cppcode}[autogobble=true, caption={IPv4 server application.},captionpos=b, morekeywords={[2]{SocketServer,EchoServerContextFactory,listen}}]
#include "EchoServerContextFactory.h"
#include <SemanticLog.h>
#include <net/in/stream/legacy/SocketServer.h>

int main(int argc, char* argv[]) {
Expand All @@ -15,16 +16,16 @@
const core::socket::State& state) -> void {
switch (state) {
case core::socket::State::OK:
VLOG(1) << "EchoServer: connected to '" << socketAddress.toString() << "'";
snode::semantic::appLog().trace() << "EchoServer: connected to '" << socketAddress.toString() << "'";
break;
case core::socket::State::DISABLED:
VLOG(1) << "EchoServer: disabled";
snode::semantic::appLog().trace() << "EchoServer: disabled";
break;
case core::socket::State::ERROR:
LOG(ERROR) << "EchoServer: " << socketAddress.toString() << ": " << state.what();
snode::semantic::appLog().error() << "EchoServer: " << socketAddress.toString() << ": " << state.what();
break;
case core::socket::State::FATAL:
LOG(FATAL) << "EchoServer: " << socketAddress.toString() << ": " << state.what();
snode::semantic::appLog().critical() << "EchoServer: " << socketAddress.toString() << ": " << state.what();
break;
}
return core::SNodeC::start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
\begin{frame}[fragile]{The IPv4 Client Application}
\begin{cppcode}[autogobble=true, caption={IPv4 client application.},captionpos=b,, morekeywords={[2]{SocketClient,EchoClientContextFactory,connect}}]
#include "EchoClientContextFactory.h"
#include <SemanticLog.h>
#include <net/in/stream/legacy/SocketClient.h>

int main(int argc, char* argv[]) {
Expand All @@ -15,16 +16,16 @@
const core::socket::State& state) -> void {
switch (state) {
case core::socket::State::OK:
VLOG(1) << "EchoClient: connected to '" << socketAddress.toString() << "'";
snode::semantic::appLog().trace() << "EchoClient: connected to '" << socketAddress.toString() << "'";
break;
case core::socket::State::DISABLED:
VLOG(1) << "EchoClient: disabled";
snode::semantic::appLog().trace() << "EchoClient: disabled";
break;
case core::socket::State::ERROR:
LOG(ERROR) << "EchoClient: " << socketAddress.toString() << ": " << state.what();
snode::semantic::appLog().error() << "EchoClient: " << socketAddress.toString() << ": " << state.what();
break;
case core::socket::State::FATAL:
LOG(FATAL) << "EchoClient: " << socketAddress.toString() << ": " << state.what();
snode::semantic::appLog().critical() << "EchoClient: " << socketAddress.toString() << ": " << state.what();
break;
}
return core::SNodeC::start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
\begin{frame}[fragile]{WebSocket Client-Application}
\begin{cppcode}[autogobble=true, caption={WebSocket Client-Application.},captionpos=b,morekeywords={[2]{upgrade,connect,Request,Response}}]
#include "web/http/legacy/in/Client.h"
#include <SemanticLog.h>

using LegacyClient = web::http::legacy::in::Client;
using Request = LegacyClient::Request;
using Response = LegacyClient::Response;

const LegacyClient legacyClient(
[](const std::shared_ptr<Request>& req) -> void { // Connection start and therefore also Request start
LOG(INFO) << "OnRequestBegin";
snode::semantic::appLog().info() << "OnRequestBegin";
req->set("Sec-WebSocket-Protocol", "echo");
req->upgrade("/ws/", "websocket",
[](const std::shared_ptr<Request>& req,
const std::shared_ptr<Response>& res) -> void {
VLOG(1) << "OnResponse";
snode::semantic::appLog().trace() << "OnResponse";
req->upgrade(res, [](bool success) -> void {
// Failure processing (logging)
});
});
},
[](const std::shared_ptr<Request>& req) -> void {// Connection and therefore also Request end
LOG(INFO) << "OnRequestEnd";
snode::semantic::appLog().info() << "OnRequestEnd";
}
);

Expand Down
4 changes: 3 additions & 1 deletion slides/020-snodec-ueberblick/09000_test.tex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
% \begin{cppcode}[autogobble=true,alsoletter={?_},
% columns=fullflexible,
% morekeywords={using},morekeywords={[2]{SocketContext,Test}}]
% #include <SemanticLog.h>
%
% class EchoServerContext : public core::socket::stream::SocketContext {
% public:
% using core::socket::stream::SocketContext::SocketContext<Test>; // constructor inheritance (since C++11)
Expand All @@ -43,7 +45,7 @@
%
% std::size_t<int> junkLen = readFromPeer(junk, 4096);
% if (junkLen > 0) {
% VLOG(0) << "Data to reflect: " << std::string(junk, junkLen);
% snode::semantic::appLog().trace() << "Data to reflect: " << std::string(junk, junkLen);
% sendToPeer(junk, junkLen);
% }
% return junkLen;
Expand Down