- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Java/C socket communication
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2007 02:50 AM
тАО03-30-2007 02:50 AM
I want to send through the socket a sequence of serialized objects. I know that in Java allows to do it through ObjectInputStream and ObjectOutputStream classes.
I would like to know if C language provides correspondant functions/libraries.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2007 05:32 AM
тАО03-30-2007 05:32 AM
Re: Java/C socket communication
Since C is not an object-oriented language, there is obviously no way object serialization can be part of the language. Even C++ does not have built in serialization, but various people have rolled their own. Here's one I stumbled on:
http://www.codeproject.com/cpp/serialization_primer3.asp
It is certainly possible in C to send and receive data through sockets, and that data could no doubt be made to conform to some serialization protocol, but one would have to know a great deal about the details of that protocol to do so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2007 07:37 PM
тАО04-01-2007 07:37 PM
Re: Java/C socket communication
even if C is not an object oriented language, it is possible to create raw objects through "struct" variables. This is the reason of my question.
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2007 07:38 PM
тАО04-01-2007 07:38 PM
Re: Java/C socket communication
even if C is not an object oriented language, it is possible to create raw objects through "struct" variables. This is the reason of my question.
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2007 07:26 PM
тАО04-02-2007 07:26 PM
SolutionC language does not provide such functions. It provides the basic socket functions. You can use these to write the protocol.
A C struct can be send to the socket with the send function:
struct {
int a;
char b[5];
} st;
send (socket , &st , sizeof (st) , 0);
and received with:
recv (socket , &st , sizeof (st) , 0);
(recv is not so simple because you must ensure that all data is received)
The hard thing is that this is not system independent. You probably know that C int size is system dependent, a second thing is data alignment. On VMS you can suppres data alignement with:
#pragma member_alignment __save
#pragma __nomember_alignment
struct ...
#pragma member_alignment __restore
The third thing is the byte order of data in memory (big or little endian). The data on VMS is little endian (low byte first). But network and Java use big endian (most significant byte first). So you must deal with this.
You can do this on the C part using the functions htonl,htons and ntohl,ntohs. These functions convert the host byte order to the network byte order and viceversa. The functions are portable (on systems that use big endian byte order they do nothing). When you use these functions sending and receiving data is not so simple as in the first example. You must know the structure and convert each part to the right order and then send to the socket. After receiving the data you must convert the parts to the host byte order.
This is also posible on the Java side. This means that you have to rewrite the methods for reading and writing primitive data types of an implementation of the DataInput and DataOutput interfaces. You cant use the methods readObject and writeObject of the ObjectOutputStream and ObjectInputStream.
One solution (maybe the best, but depends on yours implementation) is to convert all in ascii strings and send over the network only plain text and never binary data.
Bojan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2007 07:46 PM
тАО04-02-2007 07:46 PM
Re: Java/C socket communication
I will follow the last solution you propose.
I would convert the data in XML format, also taking into account that Java provides native libraries to manage it.
Many Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2007 08:14 PM
тАО04-02-2007 08:14 PM
Re: Java/C socket communication
XML is a good solution. It is system and language independent and it is a defacto standard.
On VMS you can use one of these XML packages:
expat - source ready to be compiled on VMS http://expat.sourceforge.net/
libxml2 - available on the freeware CD http://h71000.www7.hp.com/freeware/freeware80/libxml2-2_6_24/
xerces - apache XML parser
http://h71000.www7.hp.com/openvms/products/ips/xml/
The packages are sorted by complexity. Expat is the simpliest.
Bojan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2007 01:58 AM
тАО04-03-2007 01:58 AM
Re: Java/C socket communication
TCP is a stream protocol. There are no record delimiters, and no requirements to deliver data as a single packet. The client can receive anything from one byte from a larger message to multiple messages in one receive operation.
You might send over the "datagram":
[TCP is a stream protocol]
And the receiver might receive:
[T][CP is a][str]eam protoco][l]
This causes problems if the client is not accepting and correctly processing these partial messages.
And yes, I'd also avoid rolling my own protocol if I can manage it. I'd look to send over XML or set up an RSS feed or such.
The Freeware V8.0 port of libxml2 is getting a little old and crufty, but it does work. 2.6.27 is current. Re-porting the latest sources from http://www.xmlsoft.org/ isn't a big deal -- the Freeware port of libxml2 is one that I generated while I was kitting that Freeware distro, so I tossed it on. (There are source code examples, doc and such over at the xmlsoft site, too.)
Stephen Hoffman
HoffmanLabs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2007 02:24 AM
тАО04-04-2007 02:24 AM
Re: Java/C socket communication
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2009 02:26 AM
тАО02-04-2009 02:26 AM