TOBI plaform TCP server example.
#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <tobiplatform/TPSocket.hpp>
int main(void) {
std::string message;
if(socket.Open(true) == false) {
std::cout << "Error: cannot open" << std::endl;
return 1;
}
if(socket.Bind("0.0.0.0", "8001") == false) {
std::cout << "Error: cannot bind" << std::endl;
return 1;
}
if(socket.Listen() == false) {
std::cout << "Error: cannot listen" << std::endl;
return 1;
}
if(socket.Accept(&endpoint) == false) {
std::cout << "Error: cannot accept" << std::endl;
return 1;
}
std::cout << "Endpoint connected: " << socket.remote.address << std::endl;
endpoint.
Send(
"My dear client, send me something to die.\n");
std::cout << "Received: " << message << std::endl;
socket.Close();
return 0;
}