-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
65 lines (59 loc) · 1.29 KB
/
Copy pathserver.c
File metadata and controls
65 lines (59 loc) · 1.29 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
#include <signal.h>
#define PUERTO 8000 //numero del puerto
#define MSGSIZE 1024 /* longitud de los mensajes */
main(argc, argv)
int argc;
char *argv[];
{
char mensaje[MSGSIZE];
int i;
int s, ns;
struct sockaddr_in sin;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ //asignacion
perror("error socket");
exit(1);
}
bzero(&sin, sizeof(sin)); // llenado de parametros del servidor
sin.sin_family=AF_INET;
sin.sin_port=htons(PUERTO);
sin.sin_addr.s_addr=htonl(INADDR_ANY);
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) == -1) //creando socket
{
perror("tomd: bind");
exit(1);
}
if (listen(s, 5) == -1) //escuchando por el socket
{
perror("tomd: listen");
exit(1);
}
/* i = 0; */
/* while(i < 1) */
while(1)
{
if ((ns = accept(s, 0, 0)) == -1) //peticion de servicio aceptada
{
perror("error en conexion");
exit(1);
}
/* while(1)
{ */
if ( recv(ns, mensaje, MSGSIZE, 0) == -1)
{
perror("recvfrom");
exit(1);
}
++i;
printf("=> %s\n", mensaje);
/* printf ("bye"); */
/* } */
close(ns);
}
}
/*mata proceso padre con senial externa*/