-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
31 lines (21 loc) · 713 Bytes
/
server.c
File metadata and controls
31 lines (21 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(){
int server_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
struct sockaddr_in bindAddr;
bindAddr.sin_addr.s_addr = INADDR_ANY;
bindAddr.sin_family = AF_INET;
bindAddr.sin_port = 9002;
bind(server_socket, (struct sockaddr*)&bindAddr, sizeof(bindAddr));
listen(server_socket, 5);
puts("Listening...");
int client_socket = accept(server_socket, NULL, NULL);
puts("Connection established");
char response[] = "Hello, mate!";
send(client_socket, response, sizeof(response), 0);
close(server_socket);
puts("connection ended");
}