Modification TCP avec write
This commit is contained in:
parent
3caaa99da2
commit
41c4a87755
8 changed files with 73 additions and 43 deletions
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
8
.idea/ProgC.iml
Normal file
8
.idea/ProgC.iml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/ProgC.iml" filepath="$PROJECT_DIR$/.idea/ProgC.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
BIN
ProgC_Q.zip
BIN
ProgC_Q.zip
Binary file not shown.
86
tsock.h
86
tsock.h
|
@ -24,6 +24,41 @@ void printbuffer(int n);
|
||||||
//-------------Définitions des fonctions-------------
|
//-------------Définitions des fonctions-------------
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
|
|
||||||
|
//-------------PRINTBUFFER
|
||||||
|
void printbuffer(int n)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (n<10)
|
||||||
|
{
|
||||||
|
printf("[----%d",n);
|
||||||
|
}
|
||||||
|
if (n>=10 & n<100)
|
||||||
|
{
|
||||||
|
printf("[---%d",n);
|
||||||
|
}
|
||||||
|
if (n>=100 & n<1000)
|
||||||
|
{
|
||||||
|
printf("[--%d",n);
|
||||||
|
}
|
||||||
|
if (n>=1000 & n<10000)
|
||||||
|
{
|
||||||
|
printf("[--%d",n);
|
||||||
|
}
|
||||||
|
if (n>=10000 & n<100000)
|
||||||
|
{
|
||||||
|
printf("[-%d",n);
|
||||||
|
}
|
||||||
|
if (n>=100000 & n<1000000)
|
||||||
|
{
|
||||||
|
printf("[%d",n);
|
||||||
|
}
|
||||||
|
if (n>=1000000)
|
||||||
|
{
|
||||||
|
printf("Trop de messages à envoyer (n>1000000 \n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
//Construction des messages
|
//Construction des messages
|
||||||
|
|
||||||
void construire_message(char *message, char motif, int lg ,int i)
|
void construire_message(char *message, char motif, int lg ,int i)
|
||||||
|
@ -31,13 +66,11 @@ void construire_message(char *message, char motif, int lg ,int i)
|
||||||
{
|
{
|
||||||
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
|
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
|
||||||
if (i>26)
|
if (i>26)
|
||||||
{
|
motif=alphabet[i%26-1];
|
||||||
motif=alphabet[i%26-1];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
motif = alphabet[i - 1];
|
||||||
motif=alphabet[i-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j=0;j<lg-5;j++)
|
for (int j=0;j<lg-5;j++)
|
||||||
{
|
{
|
||||||
|
@ -62,40 +95,7 @@ void afficher_message(char *message, int lg)
|
||||||
}
|
}
|
||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
void printbuffer(int n)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
|
|
||||||
if (n<10)
|
|
||||||
{
|
|
||||||
printf("[----%d",n);
|
|
||||||
}
|
|
||||||
if (n>=10 & n<100)
|
|
||||||
{
|
|
||||||
printf("[---%d",n);
|
|
||||||
}
|
|
||||||
if (n>=100 & n<1000)
|
|
||||||
{
|
|
||||||
printf("[--%d",n);
|
|
||||||
}
|
|
||||||
if (n>=1000 & n<10000)
|
|
||||||
{
|
|
||||||
printf("[--%d",n);
|
|
||||||
}
|
|
||||||
if (n>=10000 & n<100000)
|
|
||||||
{
|
|
||||||
printf("[-%d",n);
|
|
||||||
}
|
|
||||||
if (n>=100000 & n<1000000)
|
|
||||||
{
|
|
||||||
printf("[%d",n);
|
|
||||||
}
|
|
||||||
if (n>=1000000)
|
|
||||||
{
|
|
||||||
printf("Trop de messages à envoyer (n>1000000 \n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
//----------------Envoi UDP---------------------------
|
//----------------Envoi UDP---------------------------
|
||||||
|
@ -284,12 +284,12 @@ void ClientTCP (int port, int nb_message , int lg_msg , char* dest)
|
||||||
|
|
||||||
construire_message(message,motif,lg_msg,i);
|
construire_message(message,motif,lg_msg,i);
|
||||||
|
|
||||||
// printbuffer(i);
|
printbuffer(i);
|
||||||
afficher_message(message,lg_msg);
|
afficher_message(message,lg_msg);
|
||||||
|
|
||||||
//Envoi du message
|
//Envoi du message
|
||||||
|
|
||||||
if ((envoi=sendto(sock,message,lg_msg,0,(struct sockaddr*)&addr_distant,lg_addr_distant))==-1)
|
if ((envoi=write(sock,message,lg_msg/*,0,(struct sockaddr*)&addr_distant,lg_addr_distant)*/))==-1)
|
||||||
{
|
{
|
||||||
printf("Echec de l'envoi du message (fonction send en défaut)\n");
|
printf("Echec de l'envoi du message (fonction send en défaut)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -396,7 +396,7 @@ void ServeurTCP(int port , int nb_message, int lg_msg)
|
||||||
printf("Echec de la lecture du message entrant \n");
|
printf("Echec de la lecture du message entrant \n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
// printbuffer(i);
|
printbuffer(i);
|
||||||
afficher_message(message, lg_recv);
|
afficher_message(message, lg_recv);
|
||||||
}
|
}
|
||||||
//Fermeture connexion
|
//Fermeture connexion
|
||||||
|
|
BIN
tsock_v3
BIN
tsock_v3
Binary file not shown.
Loading…
Reference in a new issue