Changed server/client differentiation to one peer

This commit is contained in:
j4nk 2023-05-26 21:20:13 -04:00
parent 2879a442d3
commit bb510e068e
4 changed files with 24 additions and 24 deletions

2
main.c
View File

@ -240,7 +240,7 @@ int initialize_everything(char* lua_file) {
if (config.type == OCT_TYPE_SERVER) { if (config.type == OCT_TYPE_SERVER) {
OCT_LOG_INFO("Lua script is server type"); OCT_LOG_INFO("Lua script is server type");
if (!oct_network_server_init(config.port)) { if (!oct_network_node_init(config.port)) {
OCT_LOG_ERROR("Could not establish a socket on port %s\n", config.port); OCT_LOG_ERROR("Could not establish a socket on port %s\n", config.port);
return OCT_NETWORK_ERROR; return OCT_NETWORK_ERROR;
} }

View File

@ -14,23 +14,12 @@ struct {
int needs_send; int needs_send;
char recv_buffer[BUFFER_SIZE]; char recv_buffer[BUFFER_SIZE];
char send_buffer[BUFFER_SIZE]; char send_buffer[BUFFER_SIZE];
int sock_fd;
} oct_network_client;
struct {
int needs_recv;
int needs_send;
char recv_buffer[BUFFER_SIZE];
char send_buffer[BUFFER_SIZE];
int sfd; int sfd;
} oct_network_server; } oct_network_node;
int oct_network_server_init(char* port) { int oct_network_node_init(char* port) {
oct_network_server.needs_recv = 0; oct_network_node.needs_recv = 0;
oct_network_server.needs_send = 0; oct_network_node.needs_send = 0;
struct addrinfo hints; struct addrinfo hints;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -57,15 +46,15 @@ int oct_network_server_init(char* port) {
struct addrinfo *rp; struct addrinfo *rp;
for (rp = result; rp != NULL; rp = rp->ai_next) { for (rp = result; rp != NULL; rp = rp->ai_next) {
oct_network_server.sfd = socket(rp->ai_family, rp->ai_socktype, oct_network_node.sfd = socket(rp->ai_family, rp->ai_socktype,
rp->ai_protocol); rp->ai_protocol);
if (oct_network_server.sfd == -1) if (oct_network_node.sfd == -1)
continue; continue;
if (bind(oct_network_server.sfd, rp->ai_addr, rp->ai_addrlen) == 0) if (bind(oct_network_node.sfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* Success */ break; /* Success */
close(oct_network_server.sfd); close(oct_network_node.sfd);
} }
freeaddrinfo(result); freeaddrinfo(result);
@ -75,3 +64,11 @@ int oct_network_server_init(char* port) {
return 1; return 1;
} }
int oct_network_recv_msg() {
return 0;
}
int oct_network_send_msg() {
return 0;
}

View File

@ -15,8 +15,9 @@ struct oct_network_client;
struct oct_network_server; struct oct_network_server;
int oct_network_client_init(); int oct_network_node_init(char* port);
int oct_network_server_init(char* port); int oct_network_node_deinit();
int oct_network_server_deinit(); int oct_network_recv_msg();
int oct_network_send_msg();
#endif #endif

View File

@ -1,3 +1,5 @@
-- Make sure to run open_card_table with -ll 3 to see output
require("oct_utils") require("oct_utils")
require("termbox_defs") require("termbox_defs")
@ -7,7 +9,7 @@ function oct_init()
-- text["shape"] = "THIS IS A TEST SERVER"; -- text["shape"] = "THIS IS A TEST SERVER";
-- text["x"] = 50; -- text["x"] = 50;
-- text["y"] = 10; -- text["y"] = 10;
OCT_LOG_ERROR("THIS IS A TEST SERVER"); OCT_LOG_INFO("THIS IS A TEST SERVER");
return OCT_TYPE_SERVER, OCT_NOT_NEEDS_TERMBOX; return OCT_TYPE_SERVER, OCT_NOT_NEEDS_TERMBOX;
end end