File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting two java programs

 
Robert Holdcroft
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am told this takes four lines of code but no idea where to find these seeing as I am new.

Could anyone help? I will running one program on one computer and another on another computer but they must be able to talk to each other.

Thank you.

Regards.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way is set up a simple client/server. One of the programs creates a ServerSocket, then the other connects via Socket. Then set up IO streams(what to use depends on the type of data) and you are set. You will have to decide whether to use TCP or UDP. Network programming is an intermediate topic that is deep, luckily Java abstracts alot of the details for you, but it is still good to know the underlying basics.

Check out the 2 classes in the API and there should be a basic socket tutorial at java.sun.com.
[ April 24, 2006: Message edited by: Rusty Shackleford ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "connecting two programs"? I can think of several ways to understand this phrase, one of which is the client/server model described above. Perhaps you can describe how you want to connect the two programs?

Layne
 
Robert Holdcroft
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

One sits on one pc and the other program sits on another pc and the two programs talk to each other.

Or in my case, pass a variable from to the other getting a response back.

Hope this is helpful.

Thank you.

Regards.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't count on doing it in four lines, but the Sun All About Sockets tutorial is pretty good. Give it a read. Post some almost working code here if you get stuck.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic