• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting two java programs

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic