generated from joshuadahlunr/go-cmake
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Joshua Dahl edited this page Jul 27, 2023
·
5 revisions
Welcome to the simpleP2P wiki!
Check out the C or C++ API documentations!
This is the minimal code needed to get a working chat application working with the C++ API:
#include <iostream>
#define SIMPLE_P2P_IMPLEMENTATION
#include "simplep2p.hpp"
void print(p2p::Message& message) {
if(message.is_local()) // Don't print messages from ourself!
return;
// Green console colour: \x1b[32m
// Reset console colour: \x1b[0m
std::cout << "\x1b[32m" << message.sender() << ": " << message.data_string() << "\n\x1b[0m> " << std::flush;
}
int main() {
p2p::Network net(p2p::default_listen_address, "Minimal Chat!");
net.on_message += print;
std::string line;
while(true){ // Its your responsibility to keep the program alive! Networking is all done on a separate thread!
std::cout << "> " << std::flush;
std::getline(std::cin, line);
bool success = net.broadcast_message(line);
}
}```