continually sending commands and writing commands to a tcp server.
is the following code faulty:
after connection was successful:
Code:
while(1) {
ret = write(sock, CMD, sizeof(CMD));
printf("sent: %d: %s\n", ret, CMD);
ret = read(sock, buff, sizeof(buff));
if (ret > 0) {
fprintf(stdout, "recv: %d: %s\n", ret, buff);
}
[ ... do something with buff ... ]
memset(buff, 0, MAXBUFFER-1);
sleep(1);
}
what seems to happen is that the server receives the first CMD fine but after
the first time it seems not to receive it or it gets corrupted somehow.
I've made sure with tcpdump that the packet arrives and the CMD also arrives
at the server so I'm not sure what could be wrong.
in anyway, if this is not the way to continually process returned values based on
commands sent to the server, I'd be happy if you can correct me on that.
thanks.