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?
 
Ravindra76Connect With a Mentor Commented:

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
 
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
All Courses

From novice to tech pro — start learning today.