You are not logged in.
I have a project to make a simple network server and client using basic UNIX networking (sockets and the like) and I've been able to get pretty far along, but I have some questions which I can't find satisfactory answers to online. I was hoping someone more experienced could give me a hand.
Byte Orders -- So I understand the whole byte order problem, but here's what confuses: the tutorials I've read say that it should be applied to integer data. Does this mean only actual ints or also things like chars which are implemented like ints? So if I have a big chunk of chars (say read out of a file) would I have to iterate through and send it through htons() before handing it off to send?
send() and recv() buffer lengths -- if the send() length on the server side is longer than the client's recv() length then what happens to the message? Does it just become multiple messages on the client side? Or do the two need to agree on some pre-specified length? Is there some convention for what this length should be?
Thanks,
Basu
The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github
Offline
Byte orders: You need to convert all multi-byte types (int, float, ...). Chars and char arrays do not need to be converted with hton, because they're just one byte long. What do you mean by "things like chars which are implemented like ints"? How is a char implemented like an int?
send, recv: TCP (which I assume you are using) is a byte streaming protocol. This means if you send x bytes on the server and receive x/2 bytes on the client via recv, the operating system will keep the other x/2 in a buffer until you retrieve them. If you use select() to multiplex connections on the server side, you might want to only retrieve what is already available by setting recv's FD to O_NONBLOCK and iterate until you've received everything the client wants to send.
Offline