Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > socket programming

Reply
Thread Tools

socket programming

 
 
PH
Guest
Posts: n/a
 
      11-16-2003
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

 
Reply With Quote
 
 
 
 
Sidney Cadot
Guest
Posts: n/a
 
      11-16-2003
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

 
Reply With Quote
 
 
 
 
Dave Thompson
Guest
Posts: n/a
 
      11-22-2003
On Sun, 16 Nov 2003 09:20:50 +0800, PH <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments