NovusNet is a lightweight C++ networking library designed to streamline client-server communication without the complexity of larger frameworks. Ideal for indie developers and beginners, it allows setup in under 10 lines of code, enabling focus on building rather than boilerplate. While currently aimed at Linux users, it promises an easier networking experience for all.
NovusNet is a lightweight C++ networking library designed to streamline client-server communication. Geared towards indie developers and beginners, NovusNet simplifies the often complex task of setting up networking in projects, allowing developers to establish a server-client connection with minimal code—often in fewer than ten lines.
NovusNet enables effortless integration into existing projects. Below are simple code examples illustrating how to implement a basic server and client:
#include "nn.hpp"
#include <iostream>
#include <chrono>
int main(){
//runServer takes port number and the password for your server: runServer(int port, string password)
runServer(9090, "YOUR_PASSWORD");
//"onMessage" returns clientNumber and msg of any received message from any client.
onMessage([](int clientN, std::string msg){
//more detailed logic can go on here depending on what you wanna do.
std::cout << "Client " << clientN << ": " << msg << "\n";
});
//Chrono so it does no tank cpu usage and doesn't let main() return anything
while(true){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
#include "nn.hpp"
#include <iostream>
int main(){
std::string msg;
//runClient(ip,port,password) connects to a server
int client = runClient("127.0.0.1", 9090,"YOUR_PASSWORD");
//receive client id and assign it for later use (Needed for proper communication)
msg = recvMsg(client);
int clientID = std::stoi(msg);
while(true){
std::getline(std::cin,msg);
//sendMsg(string msg) sends data as a string
sendMsg(msg,clientID);
}
return 0;
}
These code snippets can also be found in the src/client.cpp and src/server.cpp files within the repository.
By using NovusNet, the focus shifts towards product development without the burden of repetitive boilerplate code, enhancing productivity in the development cycle.
No comments yet.
Sign in to be the first to comment.