Hey,
I'm pretty deep into my first UNIX networking project, but I am lacking some fundamentals still...
I send a command and read the response. What would cause me to get different read() responses when I run the same code? Like I run the program, exit, run the program, exit, run the program, exit. Sometimes I'll get the response I expect but other times I get unicode jibberish... I feel like I'm rolling the dice...
In the example below, sometimes the response is the expected one, "+++", and other times it is something like "k��־�<}�<*n�R". The jibberish changes. I've been tinkering with sleep() to see if that increases the probability of success.
1 2 3 4 5 6 7 8 9 10 11
|
char buffer[100], latiCmd[100];
size_t cmdlen;
ssize_t bytes_sent;
snprintf(latiCmd, 100, "+++\r"); //start fresh!
cmdlen = sizeof(latiCmd);
bytes_sent = send(latisockfd,latiCmd,cmdlen,0);
printf("Sent Escape to start fresh.\n");
sleep(4);
read(latisockfd,buffer,100);
printf("Response0: %s",buffer);
|
I'm not hoping someone can correct my code... Can anybody point me in the direction of what could cause this? Do bytes just get "lost" frequently? The hardware folks said I just have to tinker with delays, but I'm not sure if that's really helping. I think I might just stay in a loop retrying the command until I read the response I want and only then move on in the program.
I suppose I'm just looking for keywords or anything that might hint me in a possible direction. I have a copy of vol 1 of stevens' unix networking book but I feel like I'm shooting in the dark!
Thanks for reading.