Networking Forums

Networking Forums > Computer Networking > Linux Networking > struct through sockets

Reply
Thread Tools Display Modes

struct through sockets

 
 
=?ISO-8859-1?Q?=D6rn_Vidarsson?=
Guest
Posts: n/a

 
      10-25-2005, 01:26 PM
My question is:

How can i send a struct through a socket?
The struct can f.x look like this:

struct any{
float ....
double ...
char ...
}

I want too send the whole structure in one command, is this posible?
If not, wich way is the "correct" way?

Thank you,
Örn
 
Reply With Quote
 
 
 
 
Phil Frisbie, Jr.
Guest
Posts: n/a

 
      10-25-2005, 04:45 PM
Örn Vidarsson wrote:

> My question is:
>
> How can i send a struct through a socket?
> The struct can f.x look like this:
>
> struct any{
> float ....
> double ...
> char ...
> }
>
> I want too send the whole structure in one command, is this posible?


Yes, but it is not the best way. For simple tests it may work fine, but
structures may have padding added to them, and the padding can be affected by
compiler switches and the platform you are compiling on. Oh, not to mention
endian differences.....

> If not, wich way is the "correct" way?


One 'correct' way is to write each element of the structure to a new buffer and
send that, then on the other end read from the buffer and save them back to the
structure.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
 
Reply With Quote
 
=?ISO-8859-1?Q?=D6rn_Vidarsson?=
Guest
Posts: n/a

 
      10-27-2005, 07:18 AM
Phil Frisbie, Jr. wrote:
> Örn Vidarsson wrote:
>
>> My question is:
>>
>> How can i send a struct through a socket?
>> The struct can f.x look like this:
>>
>> struct any{
>> float ....
>> double ...
>> char ...
>> }
>>
>> I want too send the whole structure in one command, is this posible?

>
> Yes, but it is not the best way. For simple tests it may work fine, but
> structures may have padding added to them, and the padding can be
> affected by compiler switches and the platform you are compiling on. Oh,
> not to mention endian differences.....
>
>> If not, wich way is the "correct" way?

>
> One 'correct' way is to write each element of the structure to a new
> buffer and send that, then on the other end read from the buffer and
> save them back to the structure.
>


Thanks, that's what i thought
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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
using struct igmphdr with skbuff fafarun Linux Networking 0 05-21-2009 06:15 PM
How to send a tcp packet to same machine from a kernel module by creating a sk_buff struct will_u_tellmemore Linux Networking 0 01-11-2007 12:45 PM
How can I send a struct containing a char * with a socket? Patrick Lam Linux Networking 5 04-03-2006 08:54 PM
Sending a struct over a UDP socket... Adam Balgach Linux Networking 1 09-17-2004 07:36 PM
recvfrom mis-populates sin_port in sockaddr_in struct Geoff Hungerford Linux Networking 1 06-26-2003 03:57 PM



1 2 3 4 5 6 7 8 9 10 11