This commit is contained in:
Serafim 2024-12-13 15:58:19 +03:00
parent dca2789086
commit 947bff0380
2 changed files with 9 additions and 1 deletions

Binary file not shown.

View File

@ -211,12 +211,14 @@ void log(std::string msg) {
// Returns file descriptor for server socket // Returns file descriptor for server socket
int start_socket() { int start_socket() {
int option = 1;
int server_socket = socket(AF_INET, SOCK_STREAM, 0); int server_socket = socket(AF_INET, SOCK_STREAM, 0);
setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
sockaddr_in server_address; sockaddr_in server_address;
server_address.sin_family = AF_INET; server_address.sin_family = AF_INET;
server_address.sin_port = htons(PORT); server_address.sin_port = htons(PORT);
server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_addr.s_addr = INADDR_ANY;
bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)); bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address));
if (errno == 98) { if (errno == 98) {
@ -353,6 +355,12 @@ int main() {
int server_socket = start_socket(); int server_socket = start_socket();
if (server_socket == -1) {
getch();
endwin();
return 3;
}
log("Socket created\0"); log("Socket created\0");
// Create thread to read commands // Create thread to read commands