Distributed Application - Where can I find a sample code?

I need a sample (example) code of a distributed application in Java or VC++.
ogir@zipmail.com.br
ogirAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AMD_MANCommented:

How is is distributed?  Corba? RMI? Pipes? Sockets?

There are some RMI (and CORBA) examples
in _Java 1.2 Developer's Handbook_ by Heller and Roberts.  The only problem I had getting them going was to remove the security code.  I could put in a policy file as well I guess....

That book has CORBA examples, but I haven't tried them out.  Corba could
work for hooking VC++ to Java.  But
Java rules, so why use VC++? :-)

AMD_MAN

0
ogirAuthor Commented:
I am concluding my university course, and now I am doing final report about distributed applications, it can be about CORBA, VC++, JAVA ... Then I need source code about anyone.
0
Ravindra76Commented:

I will give Java RMI..


In sun site, you will get sample examples

//Remote Interface

import java.rmi.*;

public class RMIJdbc extends Remote
{
public String getDataFromServerDatabase() throws RemoteException;
}

// Implementation class (SERVER)

import java.rmi.*;
import java.rmi.server.*;
public class RMIJdbcImpl extends UnicastRemoteObject implements RMIJdbc
{
Connection con;
PreparedStatement pst;
ResultSet rs;
String hostname="localhost"; // where you run the rmi registry
int port = 1099; // the port of the rmiregistry (by default it takes 1099)
String objectname="server"; // your object name in the naming service(rmiregistry)
public RMIJdbcImpl()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:yourdsn");
}
catch ( Exception ee)
{
ee.printStackTrace();
}

public String getDataFromServerDatabase() throws RemoteException
{
String toReturn = "";
try
{
pst = con.prepareStatement("select ename from your table where empno=?)";
pst.setInt(1,100) //Assume yourtable contains like 100 as empno and //Rameshaa as ename
rs = pst.executeQuery();
if ( rs.next())
toReturn = rs.getString(1);
retrun toReturn;

}

public static void main(String args[])
{
RMIJdbcImpl server = new RMIJdbcImpl();
server.bindInNamingService();
}
public void bindInNamingService(){
try
{
Naming.rebind("rmi://"+hostname+":"+hostpor+"/"+objectname,this);
}
Catch ( Exception eee)
{
eee.printStackTrace();
}
}
}



// CLient class
import java.rmi.server.*;
import java.rmi.*;

public class RMIClient
{
public static void main(String args[])
{
try
{
RMIJdbc obj = Naming.lookup("rmi://"+args[0]+":"+args[1]+"/"+args[2]);
System.out.println(getDataFromServerDatabase());
}catch(Exception e){
e.printStackTrace();
}
}
}



Compiling:

javac RMIJdbc.java
javac RMIJdbcImpl.java

rmic RMIJdbcImpl

javac RMIClient.java

Running:

SERVER:

start rmiregistry ( you should keep the window open until you need your server)
java RMIJdbcImpl

CLIENT:

java RMIClient localhost 1099 server

( you can give the hostname where rmiregistry is running for your server the port is rmiregistry port
these params must be the same as you give in your server);

Visit thsi for code

http://www.eurocom.od.ua/~sasha/books/java/JavaUnleashed_1.2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.