Skip to content

Commit 20a90e4

Browse files
committed
MVP sectrans -up file
1 parent 4319386 commit 20a90e4

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

Client/client

408 Bytes
Binary file not shown.

Client/client.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ int main(){
1818
char msg[1024];
1919
getmsg(msg);
2020
printf("%s\n", msg);
21+
} else if (strncmp(input, "sectrans -up", 12) == 0) {
22+
char *copy = strdup(input);
23+
char *saveptr;
24+
char *tokenized = strtok_r(copy, " ", &saveptr);
25+
for (int i = 0; i < 2 && tokenized != NULL; ++i) {
26+
tokenized = strtok_r(NULL, " ", &saveptr);
27+
}
28+
if(tokenized != NULL){
29+
char msg[1024];
30+
//open the file "tokenized"
31+
FILE *file = fopen(tokenized, "r");
32+
//write all content in msg
33+
fseek(file, 0, SEEK_END);
34+
long file_size = ftell(file);
35+
fseek(file, 0, SEEK_SET);
36+
fread(msg, 1, file_size, file);
37+
msg[file_size] = '\0';
38+
fclose(file);
39+
//send msg
40+
printf("Envoi du fichier...\n");
41+
sndmsg(msg, 8080);
42+
printf("Fichier envoyé\n");
43+
char msg2[1024];
44+
getmsg(msg2);
45+
printf("%s\n", msg2);
46+
}
2147
} else {
2248
printf("Commande inconnue\n");
2349
}

Client/test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BONJOUR JE M'APPELLE SIMON
1+
BONJOUR JE M'APPELLE SIMON

Server/database/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BONJOUR JE M'APPELLE SIMON

Server/server

304 Bytes
Binary file not shown.

Server/server.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ int main(){
4242
closedir(dir);
4343
printf("%s\n",msg);
4444
sndmsg(msg,8081);
45+
}else if (strncmp(rcv_msg,"sectrans -up", 12) == 0) {
46+
printf("Reception dun fichier\n");
47+
char *copy = strdup(rcv_msg);
48+
char *saveptr;
49+
char *tokenized = strtok_r(copy, " ", &saveptr);
50+
for (int i = 0; i < 2 && tokenized != NULL; ++i) {
51+
tokenized = strtok_r(NULL, " ", &saveptr);
52+
}
53+
if (tokenized != NULL) {
54+
char msg[1024];
55+
//create the file on the database folder
56+
const char *directory = "./database/";
57+
char filepath[1024];
58+
strcpy(filepath, directory);
59+
strcat(filepath, tokenized);
60+
FILE *file = fopen(filepath, "w");
61+
getmsg(msg);
62+
//write all msg in the new file
63+
fwrite(msg, 1, strlen(msg), file);
64+
fclose(file);
65+
printf("Fichier bien reçu\n");
66+
67+
char msg2[1024] = "Fichier bien reçu";
68+
sndmsg(msg2,8081);
69+
}
70+
}else{
71+
printf("Commande inconnue\n");
4572
}
4673
}
4774
stopserver();

0 commit comments

Comments
 (0)