update networking

This commit is contained in:
Nikola Petrov 2025-01-31 18:09:14 +01:00
parent c84f02c1e8
commit 8619918fac
3 changed files with 30 additions and 3 deletions

View File

@ -166,11 +166,21 @@ void client(std::string prefix)
std::string buffer;
buffer.resize(prefix.size() + extra_buff);
int sock = TcpSocket::connectt("petrovv.com", serverPort);
int sock = TcpSocket::connectt("petrovv.com", keyPort);
if (sock < 0)
{
return;
}
int64_t header = 0;
TcpSocket::recvt(sock, &header, sizeof(header));
TcpSocket::closet(sock);
sock = TcpSocket::connectt("petrovv.com", serverPort);
if (sock < 0)
{
// printf("Error %d", sock);
return;
}
@ -190,7 +200,7 @@ void client(std::string prefix)
// printf("id: %ld\n", ID);
TcpSocket::sendt(sock, &StartHeader, sizeof(StartHeader));
TcpSocket::sendt(sock, &header, sizeof(header));
TcpSocket::sendt(sock, &ID, sizeof(ID));
Message message;

View File

@ -114,11 +114,27 @@ void call(int sock, sockaddr_in newSocketInfo)
TcpSocket::closet(sock);
}
void send_key(int sock, sockaddr_in newSocketInfo)
{
TcpSocket::sendt(sock, &StartHeader, sizeof(StartHeader));
TcpSocket::closet(sock);
}
void listen_key()
{
int err = TcpSocket::listent("0.0.0.0", keyPort, send_key);
if (err < 0)
{
printf("ERROR %d", err);
}
}
int main()
{
sql::init();
sql::create_tables();
std::thread t(checker);
std::thread l(listen_key);
// Bind the server to a port.
int err = TcpSocket::listent("0.0.0.0", serverPort, call);
if (err < 0)

View File

@ -6,6 +6,7 @@
constexpr int64_t StartHeader = 1737720524UL;
constexpr uint16_t serverPort = 9000;
constexpr uint16_t keyPort = 9010;
enum Mess
{