5 #include <sys/socket.h>
10 int main(int argc
, char **argv
)
12 int mySocket
, clientSocket
, clientLenght
;
13 struct sockaddr_in server
, client
;
17 printf("Usage: %s <port>\n", argv
[0]);
21 mySocket
= socket(AF_INET
, SOCK_STREAM
, 0);
22 assert(mySocket
!= -1);
24 memset(&server
, 0, sizeof(server
));
25 server
.sin_family
= AF_INET
;
26 server
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
27 server
.sin_port
= htons(atoi(argv
[1]));
29 assert(bind(mySocket
, (struct sockaddr
*) &server
, sizeof(server
)) == 0);
30 assert(listen(mySocket
, 1) == 0);
32 clientLenght
= sizeof(client
);
33 //for(i = 0; i < TESTS_TOTAL; i++) {
36 printf("server: %i\n", i
);
38 clientSocket
= accept(mySocket
, (struct sockaddr
*) &client
, (unsigned int *) &clientLenght
);
39 //printf("errno: %i\n", errno);
40 assert(clientSocket
!= -1);
42 assert(recv(clientSocket
, &byte
, 1, 0) == 1);
43 assert(send(clientSocket
, &byte
, 1, 0) == 1);
44 //assert(recv(clientSocket, NULL, 0, 0) == 0);
45 //assert(send(clientSocket, NULL, 0, 0) == 0);
50 //close(clientSocket);