473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic array through sockets(network)

Hi all,

I have a doubt.
If I have 2 structures and one is parent of other , ie the child
structure is present in the parent one . And if the child structure is
declared as dynamic array in the parent , will it be possible to pass
the parent structure thru network using sockets onto other application
running on different system provided the API is known to both the
sender and the receiver.

For Ex:

struct Child
{
a: Int;
b: float;
}
struct parent
{
c : Int;
d : array of Child;(dynamic array)
}

If I make it static array, I will be able to pass it, but wat if it is
dynamic.

Thanks

Sep 13 '07 #1
1 2304
Gurur wrote:
Hi all,

I have a doubt.
If I have 2 structures and one is parent of other , ie the child
structure is present in the parent one . And if the child structure is
declared as dynamic array in the parent , will it be possible to pass
the parent structure thru network using sockets onto other application
running on different system provided the API is known to both the
sender and the receiver.
Passing raw structures over a network between different systems, is a
rather bad idea.

For starters. The C structure layout in memory, is very much compiler
dependent. Just using a different C compiler option, might affect how
struct members are aligned.
Different type of encoding can be used (T=tag, L=length, V=value), for
fixed number of tags and fixed length:

V
V
....
V

an example here could be the IPv4 header:

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

but notice the first 4 bits ('Version'), this is really a tag, so for
IPv6 header we can use a rather different header:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Source Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Destination Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Hence, IP headers are an example of TV encoding!

For fixed number of tags and variable length:

LV
LV
LV
....
LV
Notice the "Total Length" or "Payload Length" field in the IP headers,
hence the IP payload is an example of LV encoding.

For variable number of tags and variable length, we could use:

TLV
TLV
....
TLV
Another option here, is to use start and end-tags, see e.g. XML and
EDIFACT. Likewise, an IP packet over Fibre Channel:

+-----+-----------+-----------+--------//-------+-----+-----+
| | | Data Field | | |
| SOF | FC Header |<--------------------------->| CRC | EOF |
| | | Optional | Frame | | |
| | | Header(s) | Payload | | |
+-----+-----------+-----------+--------//-------+-----+-----+

here Start-Of-Frame and End-Of-Frame, can be viewed as start and end
tags. One problem with end-tags, is that you can't have a payload
containing an end-tag, so when the length is unknown, such data need to
be escaped, just like when printing '%':

printf("%%");

If I make it static array, I will be able to pass it, but wat if it is
dynamic.
When using e.g. TLV, XML or EDIFACT encoding, dynamic number of data
elements can be handled at receiver. "Nobody" is sending raw C struct's
over the wire...

--
Tor <torust [at] online [dot] no>
Sep 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1658
by: Manuel Hegemann | last post by:
Hallo, in meinem Schulprojekt, soll eine Datei, jedesmal wenn Sie aktualisiert wird auf nen FTP-Server oder für den Test auf nen Netzwerkserver gespeichert werden. Das Problem ist, dass ich noch...
6
639
by: Eric | last post by:
Does anyone know of any GOOD network programming book(s) that are C# based, as well as any online tutorials and forums on network programming? Thanks
1
5392
by: gmiley | last post by:
I have looked around in System.Net{} and System.Net.Sockets{} namespaces, but cannot seem to find a collection, or method for obtaining an active connections collection. I guess I am basically...
3
1014
by: iwdu15 | last post by:
ok, ive been going at this for a couple months now and i cant figure it out. i have a program the connects asyn to another comp with te same program using TCP sockets. then i can send text back and...
9
4878
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
3
3312
by: mislavb | last post by:
Can Dev-Cpp (Mingw) (under windows) compile network libraries: #include <unistd.h> #include <arpa/inet.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> and if yes,...
38
2919
by: Tom | last post by:
I need my data generating C program on computer #1 to export small amounts of data (one - 40 byte data structure) periodically (once per minute) to a C program on computer #2. I am considering...
2
4319
by: Dave Dean | last post by:
Hi all, I'm just starting out in sockets/network programming, and I have a very basic question...what are the 'security' implications of opening up a socket? For example, suppose I've written a...
4
2790
by: Chandra | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.