As an excercise in learning little, I’ve decided to write a simple script that writes to a socket and reads the answer.
Now the problem is, it behaves in a way I don’t get: both fprintf() and write() only actually write the data when read() finishes. Even though read() is after write().
Try adding a flush(netfd) after the fprintf() and before the read().
The filehandle is buffered and so it doesn’t actually call the system’s write() until the buffers are flushed.
(Which happens at the end currently)
Also you probably want to add a close(netfd) at the end and be checking the return values from most of those calls.
if (!(netfd = socket(host, portn)) {
fprintf(stderr, "ERROR opening socket to %s:%d\n", host, portn);
exit(1);
}
I haven’t tested this, but pretty sure it will work. Despite doing support for Little at the moment, I haven’t actually used it much. However I am a C programmer and Little is designed to be obvious to C programmers.