|
Voici le fichier main.cpp du client :
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
|
#include <iostream>
#include "../libnetwork/psocket_init.h"
#include "../definition_ports.h"
int main(int argc, char **argv) {
std::cout << "Hello, world client!" << std::endl;
int sockfd = createTCPsocketClient("localhost", PORT);
int numbytes;
char buffer[MAXDATASIZE];
printf("When you're writting something, skip the spaces.\n");
int quit = 0, len;
while (!quit){
printf("Write something:\n>");
scanf("%s", buffer);
len = strlen(buffer) + 1;
if(send(sockfd, (void *)buffer, len, 0) == -1){fprintf(stderr, "Error send\n");exit(EXIT_FAILURE);}
if(strcmp(buffer, "exit") == 0) quit = 1;
if(strcmp(buffer, "quit") == 0) quit = 1;
}
close(sockfd);
return 0;
}
|
Voilà, nous avons fini la programmation.
|
|