It just gets stuck every time I loop it. He is sitting, waiting to read, but did not read, because ... well, there is nothing to read.
Here's the read function:
int readSocket(int sockfd, char* buffer) {
FILE* file;
file = fopen("logfile.txt","a+");
char code[5];
while(1) {
int nBytes = read(sockfd, buffer, MY_BUFFER_SIZE);
fprintf(file,"S->C: %s",buffer);
strncpy(code, buffer,4);
code[4]='\0';
if (nBytes == 0) break;
memset(buffer, 0, MY_BUFFER_SIZE);
}
fclose(file);
return codeParser(atoi(code));
}
Here is what is called:
while (1) {
serverCode = readSocket(sockfd, mybuffer);
if (serverCode == 221) break;
fflush (stdout);
buffer = fgets (mybuffer, 1024, stdin);
writeSocket(sockfd, mybuffer);
}
Any suggestions?
source
share