restructure and add server/client example

This commit is contained in:
2025-01-24 10:34:04 +01:00
parent 729b475135
commit ec7b293bd5
30 changed files with 299 additions and 15 deletions

28
shared/inc/TcpSocket.hpp Normal file
View File

@@ -0,0 +1,28 @@
#include <functional>
#include <string>
#include <netinet/in.h>
#define AS_DEFAULT_BUFFER_SIZE 0x1000 /*4096 bytes*/
namespace TcpSocket
{
void setTimeout(int seconds, int sock);
ssize_t sendt(int sock, const void *bytes, size_t byteslength);
ssize_t recvt(int sock, void *bytes, size_t byteslength);
void closet(int sock);
std::string remoteAddress(sockaddr_in &address);
int remotePort(sockaddr_in &address);
int connectt(const char *host, uint16_t port);
typedef std::function<void(int sock, sockaddr_in newSocketInfo)> OnNewConnectionCallBack;
int listent(const char *host, uint16_t port, OnNewConnectionCallBack callback);
} // namespace TcpSocket