Problem de reponse provenant d un socket (timing?)

Problem de reponse provenant d un socket (timing?) - C - Programmation

Marsh Posté le 10-03-2005 à 00:53:13    

:hello: ,
 
jai 4 fonctions

Code :
  1. void login(FILE *send, FILE *read)
  2. {
  3. int length;
  4. char c;
  5. //Get the user, by calling the unix function whoami
  6. system("whoami > tmp" );
  7. .... //blabla
  8. fprintf(send,"%s",command);
  9. fflush(send);
  10. while ((c = fgetc(read)) != EOF) { putchar(c); }
  11. printf("\n" );
  12. }
  13. void logout(FILE *send, FILE *read)
  14. {
  15. int length;
  16. char c;
  17. char command[128]="LOGOUT";
  18. length = strlen(command);
  19. command[length]=0xff;
  20. fprintf(send,"%s",command);
  21. fflush(send);
  22. while ((c = fgetc(read)) != EOF) { putchar(c); }
  23. printf("\n" );
  24. }
  25. void dir(FILE *send, FILE *read)
  26. {
  27. int length;
  28. char c;
  29. char command[128]="DIR";
  30. length = strlen(command);
  31. command[length]=0xff;
  32. fprintf(send,"%s",command);
  33. fflush(send);
  34. while ((c = fgetc(read)) != EOF) { putchar(c); }
  35. printf("\n" );
  36. }
  37. void gettext(FILE *send, FILE *read, char *string)
  38. {
  39.         int length;
  40.         char c;
  41.         char command[128]="GETTEXT ";
  42.         strcat (command,string);
  43.         length = strlen(command);
  44. command[length] = 0xff;
  45.         fprintf(send,"%s",command);
  46. fflush(send);
  47. FILE *out = fopen (string,"w+" );
  48. int len;
  49. char buffer[1024];
  50. while((len = fread(buffer,1,sizeof(buffer),read)) > 0)
  51. {
  52.      fwrite(buffer,1,len,out);
  53. }
  54. fclose(out);
  55.         //while ((c = fgetc(read)) != EOF) { putchar(c); }
  56.         //printf("\n" );
  57. }


 
Elle marchent toutes lorsquelle sont lancee individulement.
LOGIN DIR LOGOUR marche aussi
par contre la ou sa coince cest
LOGIN DIR GETTEXT filex LOGOUT
 
la reponse du DIR est integre dans GETTEXT car je me retrouve a la sortie du fichier out (dans la fonciton GETTEXT) avec ca :
 
vi scorex

Code :
  1. -rw-------   1 cp341    comp        2490 Mar  1  2002 test.binary^M
  2. -rw-------   1 cp341    comp        2335 Mar  5  2002 test.text^M
  3. -rw-r--r--   1 cp341    unit        1413 Mar 10 10:45 score70^M
  4. ACK  Opened file OK\3771                          Thu Mar 10 10:45:09 2005 Connect^M
  5. 1                          Thu Mar 10 10:45:10 2005 LOGIN cmd^M
  6. 1                          Thu Mar 10 10:44:12 2005 LOGOUT cmd^M
  7. 0                                                   GETTEXT cmd^M
  8. 0                                                   PUTTEXT cmd^M
  9. 0                                                   GETBINARY cmd^M
  10. 0                                                   PUTBINARY cmd^M
  11. 1                          Thu Mar 10 10:44:12 2005 DIR cmd^M
  12. 0                                                   DELETE cmd^M
  13. 1                          Thu Mar 10 10:20:37 2005 Fetch score^M
  14. 0                                                   busy handling^M
  15. 0                                                   fetch and return test.binary^M
  16. 0                                                   fetch and return test.text^M
  17. 0                                                   replace a file^M
  18. 0                                                   put text twice^M
  19. 0                                                   fetch binary twice^M
  20. 0                                                   mixed operations^M
  21. 0                                                   delete two or more^M
  22. 0                                                   fetch test.text as text and return it as binary^M
  23. 0                                                   fetch test.binary as binary and return it as text^M
  24. Total 5^M
  25. **** Server timed out ****\377
  26. ~
  27. ~
  28. ~
  29. ~
  30. ~
  31. ~
  32. ~
  33. ~
  34. ~
  35. ~
  36. ~
  37. ~
  38. ~
  39. ~
  40. "score70" [Incomplete last line] 25 lines, 1678 characters (2 null)


 
le listing est au debut alors qu il devriat etre afficher a lecran, pas dans le ficier, j imagine donc que la fonction GETTEXT est lance avant que DIR resoit ca reponse :/
quelle est la methode a suivre dans ce cas ?
    [:dams86]


Message édité par xiluoc le 10-03-2005 à 00:53:47
Reply

Marsh Posté le 10-03-2005 à 00:53:13   

Reply

Marsh Posté le 10-03-2005 à 02:59:56    

Code :
  1. ACK  Opened file OKÿ1                          Thu Mar 10 12:55:55 2005 Connect<CR><LF>
  2. 1                          Thu Mar 10 12:55:55 2005 LOGIN cmd<CR><LF>
  3. 1                          Thu Mar 10 12:44:15 2005 LOGOUT cmd<CR><LF>
  4. 0                                                   GETTEXT cmd<CR><LF>
  5. 0                                                   PUTTEXT cmd<CR><LF>
  6. 0                                                   GETBINARY cmd<CR><LF>
  7. 0                                                   PUTBINARY cmd<CR><LF>
  8. 1                          Thu Mar 10 10:44:12 2005 DIR cmd
  9. 0                                                   DELETE cmd<CR><LF>
  10. 1                          Thu Mar 10 12:44:14 2005 Fetch score<CR><LF>
  11. 0                                                   busy handling<CR><LF>
  12. 0                                                   fetch and return test.binary<CR><LF>
  13. 0                                                   fetch and return test.text<CR><LF>
  14. 0                                                   replace a file<CR><LF>
  15. 0                                                   put text twice<CR><LF>
  16. 0                                                   fetch binary twice<CR><LF>
  17. 0                                                   mixed operations<CR><LF>
  18. 0                                                   delete two or more<CR><LF>
  19. 0                                                   fetch test.text as text and return it as binary<CR><LF>
  20. 0                                                   fetch test.binary as binary and return it as text<CR><LF>
  21. Total 5<NULL>
  22. ACK Service completeÿ


 
le ÿ reprensente la fin d une commande (0xff)
NULL la fin du fichier text.
 
jaimerai afficher les messages du server : ACK  Opened file OK et ACK Service complete
et recuperer le fichier se terminant par NULL pour l ecrire dans un autre fichier.
 
Quel est le meilleur moyen pour lire ce text sachant qu avec des buffers sa serait mieux, le problem ce que mon stream envoit un NULL et du coup fgets ne convient pas.
 
dans ce cas dois je vraiment lire via buffer ou char par char est convenable?
(les fichiers ne depasseront pas 10 kb)
 
http://www.gnu.org/software/libc/m [...] Input.html

Warning: If the input data has a null character, you can't tell. So don't use fgets unless you know the data cannot contain a null. Don't use it to read files edited by the user because, if the user inserts a null character, you should either handle it properly or print a clear error message. We recommend using getline instead of fgets.


Message édité par xiluoc le 10-03-2005 à 09:49:48
Reply

Marsh Posté le 10-03-2005 à 09:49:57    

up

Reply

Marsh Posté le 10-03-2005 à 09:54:57    

((c = fgetc(read)) != EOF)
 
c doit être un int.

Reply

Marsh Posté le 10-03-2005 à 09:57:57    

donc tant pis pour le buffer?
 
ps: arf ok
et sinon pour lire le stream ?


Message édité par xiluoc le 10-03-2005 à 10:11:08
Reply

Marsh Posté le 10-03-2005 à 13:11:30    

up

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed