NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>

void lister_arb(char *rep)

{

DIR *dir;

struct dirent *ent;

dir = opendir(rep);

if(dir == NULL)

return;

fprintf(stdout,"%s :n",rep);

while((ent = readdir(dir)) != NULL)

fprintf(stdout," %sn",ent->d_name);

fprintf(stdout,"n");

closedir(dir);

}

void lister_trie(char *rep)

{

struct dirent **ent;

int n;

int i;

n = scandir(rep, &ent, 0, alphasort);

if (n < 0)

perror("scandir");

else {

fprintf(stdout,"%s :n",rep);

for(i=0;i<n;i++)

{

printf("%sn", ent[i]->d_name);

free (ent [i]);

}

free (ent);

}

}


int main(int argc, char** argv )
{
int sockClient,sockfdServer,clilen,chilpid,ok,nleft,nbwriten,choixl;
char choix,choix1,nomRepertoire[30],msgResultReperoire[80];
struct sockaddr_in cli_addr,serv_addr;

if (argc!=3) {printf ("usage socket_client server portn");exit(0);}


/*
* partie client
*/
printf ("client startingn");

/* initialise la structure de donnee */
bzero((char*) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
serv_addr.sin_port = htons(atoi(argv[2]));

/* ouvre le socket */
if ((sockClient=socket(AF_INET,SOCK_STREAM,0))<0)
{printf("socket errorn");exit(0);}

/* effectue la connection */
if (connect(sockClient,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)
{printf("socket errorn");exit(0);}
do{

printf("n");



printf("┌──────────────────────────────────────────────────────────────────────────────┐n");

printf("│ │n");

printf("│ │n");

printf("│ MENU │n");

printf("│ │n");

printf("├───────┬──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ │ │n");

printf("│ 1 │ LISTER LE CONTENU DU REPERTOIRE │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 2 │ AJOUTER UN SOUS REPERTIORE AVEC DEUX FICHIERS │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 3 │ SUPPRIMER UN REPERTOIRE │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 4 │ SUPPRIMER UN FICHIER │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 5 │ POUR QUITTER │n");

printf("│ │ │n");

printf("└───────┴──────────────────────────────────────────────────────────────────────┘n");



printf("VIUELLEZ SAISIR VOTRE CHOIX: n");





choix=getchar();



//}while(choix != '1' || choix != '2' || choix!='3' || choix!='4' || choix!='5');

write (sockClient,&choix,1);

switch(choix){
case '1':
printf(" CHOISIR MODE AFFICHAGE :n");



printf("├───────┬──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ │ │n");

printf("│ 1 │ Liste Arbitraie │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 2 │ List Trie │n");

printf("│ │ │n");

printf("├───────┼───────────────────────────────────────────────────────────────────── |n");

scanf("%d",&choixl);

switch(choixl)

{

case 1:

{

lister_arb(".");//LISTER LE REPERTOIRE COURANT

break;

}

case 2:

{



lister_trie(".");//LISTE TRIE DU REPERTOIRE COURANT



break;

}

}
break;
case '2':
printf("Entrer le nom du Sous repertoiren");
scanf("%s",nomRepertoire);
send(sockClient,nomRepertoire,30,0);
recv(sockClient,msgResultReperoire,80,0);
printf("%sn",msgResultReperoire);
break;
case '3':
printf("le repertoire que vous voulez supprimer:n");
scanf("%s",nomRepertoire);
send(sockClient,nomRepertoire,30,0);
recv(sockClient,msgResultReperoire,80,0);
printf("%sn",msgResultReperoire);
break;
case '4':

printf("Entrez le nom du sous repertoire contenant ce fichier:n");
scanf("%s",nomRepertoire);
send(sockClient,nomRepertoire,30,0);

printf("n");

printf("Vous Voulez Supprimer :n");

printf("├───────┬──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ │ │n");

printf("│ 1 │ LE PREMIER FICHIER │n");

printf("│ │ │n");

printf("├───────┼──────────────────────────────────────────────────────────────────────┤n");

printf("│ │ │n");

printf("│ 2 │ LE DEUXIÉME FICHIER │n");

printf("│ │ │n");

printf("├───────┼───────────────────────────────────────────────────────────────────── |n");

printf("Entrer votre choix:");
choix1=getchar();
choix1=getchar();
write (sockClient,&choix1,1);
recv(sockClient,msgResultReperoire,80,0);
printf("%sn",msgResultReperoire);
break;

case '5':

break;

case '6':
printf("La connection entre le serveur et le client est stopé....n");
break;

default:
printf("votre choix est incompatiblen");
break;

}

}while(1);
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.