This commit is contained in:
2026-02-02 00:00:40 -06:00
parent 457f962434
commit 9f6fba4fc1
5 changed files with 143 additions and 0 deletions

36
server.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
int main(void){
// Declare variables
const char *server_ip = "127.0.0.1";
const int server_port = 8080;
char client_message[1024];
char server_message[1024];
// Create socket
// Bind to the set port and IP
printf("Done with binding with IP: %s, Port: %d\n", server_ip, server_port);
// Listen for clients:
const char *client_ip = "127.0.0.1";
const int client_port = 12345;
// Accept an incoming connection
printf("Client connected at IP: %s and port: %i\n", client_ip, client_port);
// Receive client's message
printf("Msg from client: %s\n", client_message);
// Respond to client
strcpy(server_message, "Hello from server");
// Close the socket
return 0;
}