473,506 Members | 17,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forming protocol messages with structure instances

Two differenet applications (running on different OS, different
compilers) are communicating thru protocol consisting of functions and
arguments.
Communication link can be TCP/IP, or serial port.

What is the best way to map structure instance to protocol messages ?

The solutions we are thinking of -
1. declare each structure member as packed, and use memcpy for struct
size.
The target application should directly memcpy this area, to the
desired structure, which is already instantiated.

2. serialize each entry with member data type, followed by value, and
transmit it over link.
Value needs to be decoded using data type flag.
1st option might not be portable.
2nd option requires extra efforts and overhead.

Is there any better alternative?
regards,
Pramod
Nov 14 '05 #1
3 1856
pramod wrote:
Two differenet applications (running on different OS, different
compilers) are communicating thru protocol consisting of functions and
arguments.
Communication link can be TCP/IP, or serial port.

What is the best way to map structure instance to protocol messages ?

The solutions we are thinking of -
1. declare each structure member as packed, and use memcpy for struct
size.
The target application should directly memcpy this area, to the
desired structure, which is already instantiated.
Portability problems:
Endian issues
Data type size issues (possibly less of a problem in C99)

2. serialize each entry with member data type, followed by value, and
transmit it over link.
Value needs to be decoded using data type flag.
Indeed.


1st option might not be portable.
Right.
2nd option requires extra efforts and overhead.
Also correct.
About all you can do is come up with the lightest weight
serialization/deserialization protocol (or use some third party software
to help you achieve this).

Is there any better alternative?


Not really. ;-(
Standard C is much more concerned with cross platform source
compatibility than data compatibility (at least partially due to
historical reasons).

HTH,
--ag
--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Nov 14 '05 #2
sp********@yahoo.com (pramod) wrote:
# Two differenet applications (running on different OS, different
# compilers) are communicating thru protocol consisting of functions and
# arguments.
# Communication link can be TCP/IP, or serial port.
#
# What is the best way to map structure instance to protocol messages ?
#
# The solutions we are thinking of -
# 1. declare each structure member as packed, and use memcpy for struct
# size.
# The target application should directly memcpy this area, to the
# desired structure, which is already instantiated.

Not at all safe with different compilers.

# 2. serialize each entry with member data type, followed by value, and
# transmit it over link.
# Value needs to be decoded using data type flag.

You might want to look into ASN-1 and its encoding rules, rather than start
over from scratch. ASN software and libraries are available.

# Is there any better alternative?

If at all possible encode into an ASCII string. Much more likely to be
portable, avoids byte order problems, eases debugging, and if you redirect
traffic to a file, you can use off the shelf programming tools to look at it.
The overhead of network communications will likely overwhelm encoding
and decoding costs.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
If you plan to shoplift, let us know.
Thanks
Nov 14 '05 #3
Derk Gwen <de******@HotPOP.com> wrote in message news:<vu************@corp.supernews.com>...

# 2. serialize each entry with member data type, followed by value, and
# transmit it over link.
# Value needs to be decoded using data type flag.

You might want to look into ASN-1 and its encoding rules, rather than start
over from scratch. ASN software and libraries are available.


FYI a lot of ASN.1 compilers and libraries are listed at
http://asn1.elibel.tm.fr/links/#tools

O. Dubuisson
Nov 14 '05 #4

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

Similar topics

6
2920
by: LRW | last post by:
Because I've had recipients of our newsletter tell us they can't (or won't) receive HTML e-mail, I found out how to make an e-mail that sends both HTML and a plaintext version in a multipart...
8
1459
by: Torsten Mohr | last post by:
Hi, i created a new type and implemented the sequence protocol for it, or to be more precise the functions to get the sequence length, to read a value and to assign a value to an item. Now i...
3
43151
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically...
12
5498
by: Laszlo Zsolt Nagy | last post by:
Hello, I would like to develop a new network protocol, where the server and the clients are Python programs. I think to be effective, I need to use TCP_NODELAY, and manually buffered transfers....
10
4967
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
1
2676
by: Benry | last post by:
Hi guys. I hope I can discuss Twisted here. If not, direct me to the correct place please. My question(s): I'm working on a custom network protocol (application layer in TCP/IP model) for a...
0
2079
by: varughmi | last post by:
A unique issue has cropped up today in a .NET program I developed. It has been working fine for over an year until now. The program makes 2 connections total - one to a UNIT instance and another...
1
2886
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
13
2265
by: Rafe | last post by:
Hi, I am in a situation where I feel I am being forced to abandon a clean module structure in favor of a large single module. If anyone can save my sanity here I would be forever grateful. My...
0
7105
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
7371
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...
1
7023
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
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,...
0
4702
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
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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
410
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.