7 #include "sys/socket.h"
8 #include "netinet/in.h"
10 #include "sys/select.h"
15 #define HELLO_MSG "Hello from the server\n"
16 #define RESPONSE_MSG "Hello from the client!\n"
18 int main(int argc
, char **argv
)
20 int sock
= socket(AF_INET
, SOCK_STREAM
, 0);
21 struct sockaddr_in sin
;
22 int salen
= sizeof(sin
);
27 // test_banner("Accept Test - Server");
29 memset(&sin
, 0, sizeof(sin
));
30 sin
.sin_family
= AF_INET
;
31 sin
.sin_port
= htons(PORT
);
33 sin
.sin_addr
.s_addr
= htonl(INADDR_ANY
); // LOOPBACK);
34 rv
= bind(sock
, (const struct sockaddr
*)&sin
, salen
);
42 printf("Listening\n");
44 newsock
= accept(sock
, (struct sockaddr
*)&sin
, &salen
);
47 printf("Accepted socket %d\n", newsock
);
49 rv
= write(newsock
, HELLO_MSG
, strlen(HELLO_MSG
));
52 printf("Written hello\n");