ajoute argument client
This commit is contained in:
parent
8f0dc28234
commit
c78915dcca
@ -17,10 +17,19 @@ int main (int argc, char * argv[]) {
|
||||
char buffer [LG_BUFFER];
|
||||
int nb_lus;
|
||||
|
||||
if (argc != 3){
|
||||
perror("Nombre d'arguments invalides, vous devez entrer deux arguments");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// Serveur auquel on se connecte
|
||||
char * hote = "127.0.0.1";
|
||||
// Port du serveur sur lequel on se connecte
|
||||
int port = 60000;
|
||||
//char * hote = "127.0.0.1";
|
||||
char * hote = argv[1];
|
||||
|
||||
// Port du serveur sur lequel on se connecte0
|
||||
//int port = 1234;
|
||||
int port = atoi(argv[2]);
|
||||
|
||||
struct hostent * hostent;
|
||||
struct servent * servent;
|
||||
|
BIN
client_echo.o
Executable file
BIN
client_echo.o
Executable file
Binary file not shown.
@ -61,14 +61,12 @@ int cree_socket_stream (const char * nom_hote, const int num_port, const char *
|
||||
else {
|
||||
adresse.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
}
|
||||
|
||||
// Pattacher un port a la socket sock
|
||||
if (bind(sock, (struct sockaddr *) & adresse, sizeof(struct sockaddr_in)) < 0) {
|
||||
close(sock);
|
||||
printf("Erreur : bind\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
@ -82,7 +80,6 @@ int affiche_adresse_socket (int sock) {
|
||||
printf("Erreur : getsockname\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf ("IP = %s, Port = %u \n", inet_ntoa(adresse.sin_addr), ntohs(adresse.sin_port));
|
||||
return 0;
|
||||
}
|
||||
@ -159,20 +156,13 @@ void traite_connexion (int sock){
|
||||
printf("J'ai lu %d bytes\n",longueur);
|
||||
// Pour le client telnet :
|
||||
//buffer[longueur-2] = '\0';
|
||||
// Avec un client autre que telnet :
|
||||
//buffer[longueur]='\0';
|
||||
|
||||
// printf("Je melange %s\n",buffer);
|
||||
//strfry(buffer);
|
||||
|
||||
// Ecrire la variable buffer sur la socket
|
||||
write(sock, buffer, longueur);
|
||||
}
|
||||
|
||||
close(sock);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
return serveur_tcp();
|
||||
}
|
||||
|
BIN
serveur_echo.o
Executable file
BIN
serveur_echo.o
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user