By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,991 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,991 IT Pros & Developers. It's quick & easy.

socket programming

P: n/a
PH
Hi,
I need a bit of explanation (or pointers to online references) on socket
programming in linux. How do I send a data structure over the internet
and how mtu affects the data flow? does the computer wait til the local
buffer reaches a treshold before it sends? if so, how do i extract each
structure with its corresponding header and body? I can find only htons
and htonl for byte ordering conversion. What do I do with a struct
that's, say, 42 or 75 bytes?

I'm new to socket programming. I hope u guys can help. Many many thanks
in advance :-)

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
PH wrote:
Hi,
I need a bit of explanation (or pointers to online references) on socket
programming in linux.


You're better off asking this in linux-specific newsgroups, or some
newsgroup related to networking. This newsgroup is about standard C, and
the C standard doesn't say anything about sockets (it's a platform-
specific library extention, originating with BSD Unix I think).

Best regards,

Sidney

Nov 13 '05 #2

P: n/a
On Sun, 16 Nov 2003 09:20:50 +0800, PH <ph******@hotpop.com> wrote:
Hi,
I need a bit of explanation (or pointers to online references) on socket
programming in linux. How do I send a data structure over the internet
and how mtu affects the data flow? does the computer wait til the local
buffer reaches a treshold before it sends?
As already said, the socket part is not Standard C and offtopic;
although I would add for generic sockets, as opposed to any Linux
specifics, I believe comp.unix.programmer is also good.
if so, how do i extract each
structure with its corresponding header and body? I can find only htons
and htonl for byte ordering conversion. What do I do with a struct
that's, say, 42 or 75 bytes?
However, all BSD-type sockets I know of transport memory contents
unchanged, so you have the issue of whether the representation of data
in memory on system is the same as that on another -- and, if in C,
*that* is ontopic; the same issue arises for fwrite'ing and fread'ing
binary files which is standard; and the answer is it's not required --
many details of the representation depend on the 'implementation', a
term of art that basically means the combination of CPU, compiler,
library, and system/OS you use, with some rare exceptions that don't
matter here; and in fact *do* vary between implementations.

If both/all ends are the same architecture e.g. Linux/GNU/x86 *and
using the same compiler/options*, you can probably get away with just
sending/recving an identically declared struct and it will work; for
any other case you probably need to worry about either defining and
converting to and from a common representation, or defining pairwise
conversions between all (current? expected? possible?) platforms; and
even for a homogenous environment it is better to do this, because
they may well become heterogenous in the future.

An obvious common (platform-independent) form is text; because of its
simplicity and ease of debugging this is used in many Internet
application formats (SMTP/mail, NNTP/news, HTTP/HTML) though by no
means all (cf SNMP). Although typically somewhat less efficient, text
is simpler to define and often to implement correctly, and in modern
applications the inefficiency is rarely a problem. This is supported
in C by s[n]printf and sscanf, and more specific routines like strtol
and even wcstombs. Remember that C requires strings to be terminated
by a null character, but it is usual to not actually send that null,
and the recv'er usually needs to (allow for and) add it.

Another possibility is a binary format like XDR (provided on many?
most? Unices as part of the "Sun" RPC = Remote Procedure Call package)
or (more complicated) ASN.1; and you can always define your own,
possibly using {n,h}to{h,n}{s,l} for network-endian integers in the
same way as the lower IP levels.
I'm new to socket programming. I hope u guys can help. Many many thanks
in advance :-)


- David.Thompson1 at worldnet.att.net
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.