Monday, November 4, 2013

I define a class, and then I instate an object of that class type. I want to send this object to another Java application running on a different computer transparently. What is the best technology to accomplish this?
share|improve this question
1 
You mean like--satellite, the Internet or AM/FM-radio? Or if not, may we see the class? Give us code dude! \o/ Anything! As long as it's still moving, a little.. –  0scar Dec 19 '09 at 0:44
 
BTW, you asked for the best technology to accomplish your question not sample code how to do it. That is why you got 3 answers for technologies to use. If you want sample code then ask for sample code and you would been provided with sample code from multiple people on how to do it using different technologies or using the same but you would have more to choose from. –  Rodney Foley May 14 '10 at 17:25

4 Answers

you can create object streams using the java api and send any serializable object. but youll have to mind that these go unencrypted through the network:
on the sender's side:
CustomObject objectToSend=new CustomObject();
Socket s = new Socket("yourhostname", 1234);
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
out.writeObject(objectToSend);
out.flush();
and on the receiving end:
ServerSocket server = new ServerSocket(1234);
Socket s = server.accept();
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
CustomObject objectReceived = (CustomObject) in.readObject();
share|improve this answer
You'll want to start by looking into serialization with the Java Serializable interface. Sun has a good article on it called Discover the secrets of the Java Serialization API.
Refer to the Java Sockets tutorial for information on actually transferring the serialized object over the network.
share|improve this answer
There are a lot of ways to do this. Here are some things to look into and you can pick the one that would work best for your application.
  • J2EE
  • RMI
  • Object Serialization pushing the bits over a Socket
  • Webservices
Pretty much any communication framework will allow you to push objects over a network in one way or another. You just need to review them and see which works for your application. A quick google should find even more methods.
share|improve this answer
A (de facto) standard to implement this would be to use a web service, for example using JAX-WSwhich is bundled in Java 6. See this tutorial for a java-first sample (i.e. using annotations). This is pretty straight forward and easy.
There are other approaches such as Serialization over a Socket, RMI, EJBs but, when working over the Internet, web services are a kind of natural choice as they rely on existing standards (SOAP, HTTP) and deal easily with firewalls (which might be a real issue for all other solutions).
share|improve this answer

No comments: