*
The moose likes Beginning Java and the fly likes Connecting two java programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Connecting two java programs" Watch "Connecting two java programs" New topic
Author

Connecting two java programs

Robert Holdcroft
Greenhorn

Joined: Apr 24, 2006
Posts: 2
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

Joined: Jan 03, 2006
Posts: 490
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 ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Robert Holdcroft
Greenhorn

Joined: Apr 24, 2006
Posts: 2
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Connecting two java programs
 
Similar Threads
Downloading a web page
Using JDBC with an applet
move tables from one computer to another?
Database file
How to take another system time?