473,606 Members | 2,877 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 2313
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
1661
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 nie mit sockets gearbeitet habe und nicht weiß wie ich das realisieren soll. das wenn aktualisiert etc. ist ja kein problem... es geht nur um die sockets!! kennt da jmd. gute seiten bei denen ich mich informieren kann oder kann mir jmd. evtl....
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
5409
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 looking for a way to produce similar output as what netstat would produce, but in a controled C# environment where those enumerated connections could be manipulated. Thanks for any help.
3
1016
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 forth, no problem. how can i send text with formatting, like different fonts, styles, colors etc. ive tried everything i casn think of but nothing seems to work....any help wiold b awsome -- -iwdu15
9
4897
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 strReturnData As String = _ System.Text.Encoding.ASCII.GetString(receiveBytes)
3
3321
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, what do I have to do to do it?
38
2955
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 having computer #1 to create two duplicate data files sequentially. (file_1.dat & file_2.dat). Then, Computer #2 tries to open file_2.dat and upon failure it opens file_1.dat.
2
4336
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 simple chat server and chat client. The server opens a socket, listens on a port, and accepts incoming connections. The clients open a socket and connect to the server. If the server receives a message from a client, it sends that message out to...
4
2804
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 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.
0
7962
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8443
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8107
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6792
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5971
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.