43 lines
854 B
C++
43 lines
854 B
C++
#include <string>
|
|
#include <netinet/in.h>
|
|
#include <cinttypes>
|
|
|
|
#define AS_DEFAULT_BUFFER_SIZE 0x1000 /*4096 bytes*/
|
|
|
|
constexpr int64_t StartHeader = 1737720524UL;
|
|
constexpr uint16_t serverPort = 9000;
|
|
|
|
enum Mess
|
|
{
|
|
RES_OK,
|
|
RES_NO,
|
|
REQ_SEND_GEN,
|
|
};
|
|
|
|
struct Message
|
|
{
|
|
Mess mess;
|
|
uint32_t data;
|
|
};
|
|
|
|
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 void(OnNewConnectionCallBack)(int sock, sockaddr_in newSocketInfo);
|
|
int listent(const char *host, uint16_t port, OnNewConnectionCallBack callback);
|
|
|
|
} // namespace TcpSocket
|