Server:
Client:codice:[...] void str_srv_echo(int sockd) { int n,file,ff; char line[MAXLINE]; char buf[MAXBUFFLEN+1]; while(1) { if ((n = recv(sockd, line, MAXLINE,0)) == 0) return; /* il client ha chiuso la connessione e inviato EOF */ printf("%s__\n",line); if(file = open(line,O_RDONLY)==-1) { printf("[%u] Error Opening file\n",file); // exit(1); } else printf("[%u] Opening file\n",file); while(ff=read(file,buf,MAXBUFFLEN)>0) { printf("Reading frome file\n"); if (send(sockd, buf, ff,0) != n) { fprintf(stderr, "errore in write"); exit(1); } } } }
Sicuramente c'è qualcosa che non va!! Ho lanciato il prog ma non mi trasferisce nessun file!! Se non esiste lo crea ma non ci scrive nulla!!codice:[...] void str_cli_echo(char* file, int sockfd) { int fout,n; char buf[MAXBUFFLEN+1]; if(write(sockfd,file,MAXBUFFLEN)<0) { perror("Errore in write"); exit(1); } if((fout=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) { perror("open output"); exit(1); } while((n=read(sockfd,buf,MAXBUFFLEN)) > 0) { if(write(fout,buf,n) < n) { perror("open output"); exit(1); } } if(n < 0) { perror("read"); exit(1); } }
Suggerimenti??![]()
![]()

Rispondi quotando