source code migrating from gitlab

This commit is contained in:
2026-05-15 15:51:41 -04:00
commit 6cf9a21574
28 changed files with 2960 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
#include "client/client.h"
#include <lwip/sockets.h>
#define PORT 9000
const char *address = "192.168.40.88";
int sendJSON(char *json, int len) {
int fd = 0, res = 0;
struct sockaddr_in server;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) {
return -1;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
res = inet_pton(AF_INET, address, &server.sin_addr);
if (res < 0) {
close(fd);
return -2;
}
res = connect(fd, (struct sockaddr *)&server, sizeof(server));
if (res < 0) {
close(fd);
return -3;
}
res = sendAll(fd, json, len);
if (res < 0) {
close(fd);
return -4;
}
close(fd);
return 0;
}
int sendAll(int sock, char *buf, int len) {
int total = 0, bytesleft = len, n = 0;
while (total < len) {
n = send(sock, buf + total, bytesleft, 0);
if (n < 0) {
break;
}
total += n;
bytesleft -= n;
}
return n == -1 ? -1 : 0;
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef CLIENT_H
#define CLIENT_H
int sendJSON(char *json, int len);
int sendAll(int sock, char *buf, int len);
#endif // !CLIENT_H