updates
This commit is contained in:
36
server.cpp
Normal file
36
server.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user