is it possible to send whole class data to another machine via socket interface?

R

rambo88

Hello.
typedef struct
{
int a, int b;
char text [10];
}IDL;
IDL msg;

in a linux c-programming, I define c-structure and send it to another
machine via socket inteface.
for example send ( socketFd , &msg, sizeof ( msg ) ) => recv ( socketfd,
&msg , sizeof ( msg );

here , I like to know how to define c-structre type in java , and how to
send to another machine.

1)
class
{
int a , int b;
String text;
} JavaIDL
JavaIDL jds; => is it possible ?

2) how to send it to another machine with whole class-data type ==> is it
possible way in java language?
send ( jds , sizeof (jds ) ==> recv ( jds, sizeof ( jds ) ;


thank you in advance.
Have a day.
 
A

Andy Fish

rambo88 said:
Hello.
typedef struct
{
int a, int b;
char text [10];
}IDL;
IDL msg;

in a linux c-programming, I define c-structure and send it to another
machine via socket inteface.
for example send ( socketFd , &msg, sizeof ( msg ) ) => recv ( socketfd,
&msg , sizeof ( msg );

this approach is very dangerous because you are relying on the internal
implementation of int being the same in both machines - you could not send
data from an intel machine to a sun machine with this program.

fortunately java provides a safe mechanism - google for
'java.io.serializable and java.io_ObjectOutputStream
 
L

lordy

rambo88 said:
Hello.
typedef struct
{
int a, int b;
char text [10];
}IDL;
IDL msg;

in a linux c-programming, I define c-structure and send it to
another machine via socket inteface.
for example send ( socketFd , &msg, sizeof ( msg ) ) => recv (
socketfd, &msg , sizeof ( msg );

this approach is very dangerous because you are relying on the
internal implementation of int being the same in both machines - you
could not send data from an intel machine to a sun machine with this
program.

fortunately java provides a safe mechanism - google for
'java.io.serializable and java.io_ObjectOutputStream

Also depending on the size, goals and distribution of your project you
may want to reuse other long established protocols and technologies for
sending objects from machine to machine, and focus your core efforts on
the unique parts of your application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top