Changed server/client differentiation to one peer
This commit is contained in:
parent
2879a442d3
commit
bb510e068e
2
main.c
2
main.c
|
@ -240,7 +240,7 @@ int initialize_everything(char* lua_file) {
|
|||
|
||||
if (config.type == OCT_TYPE_SERVER) {
|
||||
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);
|
||||
return OCT_NETWORK_ERROR;
|
||||
}
|
||||
|
|
|
@ -14,23 +14,12 @@ struct {
|
|||
int needs_send;
|
||||
char recv_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;
|
||||
} oct_network_server;
|
||||
} oct_network_node;
|
||||
|
||||
int oct_network_server_init(char* port) {
|
||||
oct_network_server.needs_recv = 0;
|
||||
oct_network_server.needs_send = 0;
|
||||
int oct_network_node_init(char* port) {
|
||||
oct_network_node.needs_recv = 0;
|
||||
oct_network_node.needs_send = 0;
|
||||
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
@ -57,15 +46,15 @@ int oct_network_server_init(char* port) {
|
|||
struct addrinfo *rp;
|
||||
|
||||
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);
|
||||
if (oct_network_server.sfd == -1)
|
||||
if (oct_network_node.sfd == -1)
|
||||
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 */
|
||||
|
||||
close(oct_network_server.sfd);
|
||||
close(oct_network_node.sfd);
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
@ -75,3 +64,11 @@ int oct_network_server_init(char* port) {
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int oct_network_recv_msg() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int oct_network_send_msg() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,9 @@ struct oct_network_client;
|
|||
struct oct_network_server;
|
||||
|
||||
|
||||
int oct_network_client_init();
|
||||
int oct_network_server_init(char* port);
|
||||
int oct_network_server_deinit();
|
||||
int oct_network_node_init(char* port);
|
||||
int oct_network_node_deinit();
|
||||
int oct_network_recv_msg();
|
||||
int oct_network_send_msg();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
-- Make sure to run open_card_table with -ll 3 to see output
|
||||
|
||||
require("oct_utils")
|
||||
require("termbox_defs")
|
||||
|
||||
|
@ -7,7 +9,7 @@ function oct_init()
|
|||
-- text["shape"] = "THIS IS A TEST SERVER";
|
||||
-- text["x"] = 50;
|
||||
-- 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;
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue