Modification TCP avec write

This commit is contained in:
BQUINTAN 2020-04-14 17:45:28 +02:00
parent 3caaa99da2
commit 41c4a87755
8 changed files with 73 additions and 43 deletions

2
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

8
.idea/ProgC.iml Normal file
View 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
View 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
View 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
View 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>

Binary file not shown.

86
tsock.h
View file

@ -24,6 +24,41 @@ void printbuffer(int n);
//-------------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
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";
if (i>26)
{
motif=alphabet[i%26-1];
}
motif=alphabet[i%26-1];
else
{
motif=alphabet[i-1];
}
motif = alphabet[i - 1];
for (int j=0;j<lg-5;j++)
{
@ -62,40 +95,7 @@ void afficher_message(char *message, int lg)
}
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---------------------------
@ -284,12 +284,12 @@ void ClientTCP (int port, int nb_message , int lg_msg , char* dest)
construire_message(message,motif,lg_msg,i);
// printbuffer(i);
printbuffer(i);
afficher_message(message,lg_msg);
//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");
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");
exit(1);
}
// printbuffer(i);
printbuffer(i);
afficher_message(message, lg_recv);
}
//Fermeture connexion

BIN
tsock_v3

Binary file not shown.