hello java experts,

I have made a program for remote method invocation but i am not
able to do get output even i am able to do registry
socket error it shows during run made.
plz help me out if anyone knows..........
1)name:AuhorServer

import java.rmi.*;   
public interface AuthorServer extends Remote
{
    /* Declare the remote method. */
    String insertDetails(String authorID, String lastName, String firstName, String phone, String address, String city, String state, String zip) throws RemoteException;   
}

2) AuthorServerImpl

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
public class AuthorServerImpl extends UnicastRemoteObject implements AuthorServer
{
    static ResultSet result;
    static Connection con;
    static PreparedStatement stat;

    /* Define the default constructor of the Impl class */
    public AuthorServerImpl() throws RemoteException
    {
        super();
    }

    /* Define the remote method */
    public String insertDetails(String authorID, String lastName, String firstName, String phone, String address, String city, String state, String zip) throws RemoteException
    {

        int rowsAffected = 0;
        String sReturn = "fail";
        try
        {
            /* Register the database driver. */
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            /* Create the connection. */
            con=DriverManager.getConnection("jdbc:odbc:MyDataSource", "Administrator", "");

            /* Create the prepareStatement to insert the value in the database. */

stat=con.prepareStatement("insert into authors values (?, ?, ?, ?, ?,?,?,?)");
            stat.setString(1, authorID);

            stat.setString(2, lastName);

            stat.setString(3, firstName);

            stat.setString(4, phone);

            stat.setString(5, address);

            stat.setString(6, city);

            stat.setString(7, state);

            stat.setString(8, zip);

            rowsAffected = stat.executeUpdate();
            if(rowsAffected>0)
            {
                sReturn = "success";
            }
        }
        catch(Exception v)
        {
            System.out.println("Error at value insert" + v);
        }
        return sReturn;
    }

    /* Define the main() method */
    public static void main(String args[])
    {
        /* Set the security manager. */
        System.setSecurityManager(new RMISecurityManager());
        try
        {
            /* Create the instance of the Impl class. */
            AuthorServerImpl instance = new AuthorServerImpl();
            /* Bind the server object to the RMI registry. */
            Naming.rebind("AuthorServer", instance);
            System.out.println("Server Registered");
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

3)

import javax.swing.*;
import java.rmi.*;
import java.awt.event.*;
import java.awt.*;
public class Client
{
    /* Declare the variables */
    static JFrame frame;
    static JPanel panel;
    static JPanel panel1;

    JLabel labelAuthorID;
    JLabel labelLastName;
    JLabel labelFirstName;
    JLabel labelPhone;
    JLabel labelAddress;
    JLabel labelCity;
    JLabel labelState;
    JLabel labelZip;

    JTextField textAuthorID;
    JTextField textLastName;
    JTextField textFirstName;
    JTextField textPhone;
    JTextField textAddress;
    JTextField textCity;
    JTextField textState;
    JTextField textZip;

    JButton submit;

    static String authorID;
    static String lastName;
    static String firstName;
    static String phone;
    static String address;
    static String city;
    static String state;
    static String zip;

    /* Define the default constructor */
    public Client()
    {
        /* Create the JFrame */
        frame=new JFrame("Earnest Publishing House");
        panel = new JPanel();
        panel1 = new JPanel();
        /* Set the Layout managers */
        panel.setLayout(new GridLayout(8,2));
        panel1.setLayout(new GridLayout(1,1));
        frame.setVisible(true);
        frame.setSize(400, 400);
        frame.getContentPane().setLayout(new BorderLayout());

        /* Define the swing components on the JFrame */ 
        labelAuthorID = new JLabel("Author ID");
        labelLastName = new JLabel("Last Name");
        labelFirstName = new JLabel("First Name");
        labelAddress = new JLabel("Phone");
        labelPhone = new JLabel("Address");
        labelCity = new JLabel("City");
        labelState = new JLabel("State");
        labelZip = new JLabel("Zip");

        textAuthorID = new JTextField(5);
        textLastName = new JTextField(15);
        textFirstName = new JTextField(15);
        textPhone = new JTextField(10);
        textAddress = new JTextField(50);
        textCity = new JTextField(10);
        textState = new JTextField(10);
        textZip = new JTextField(6);

        submit = new JButton("Submit");

        /* Add the swing components on the panel */ 
        panel.add(labelAuthorID);
        panel.add(textAuthorID);
        panel.add(labelLastName);
        panel.add(textLastName);
        panel.add(labelFirstName);
        panel.add(textFirstName);
        panel.add(labelPhone);
        panel.add(textPhone);
        panel.add(labelAddress);
        panel.add(textAddress);
        panel.add(labelCity);
        panel.add(textCity);
        panel.add(labelState);
        panel.add(textState);
        panel.add(labelZip);
        panel.add(textZip);
        panel1.add(submit);
        ButtonListener blisten = new ButtonListener();
        submit.addActionListener(blisten);
        frame.getContentPane().add(new JPanel(), BorderLayout.WEST);
        frame.getContentPane().add(new JPanel(), BorderLayout.EAST);
        frame.getContentPane().add(panel, BorderLayout.CENTER);
        frame.getContentPane().add(panel1, BorderLayout.SOUTH);
    }
    /* Create a ButtonListener class */
    class ButtonListener implements ActionListener
    {
        /* Define the actionPerformed() method */
        public void actionPerformed(ActionEvent evt)
        {
            JButton source=(JButton)evt.getSource();
            MyDialog myDialog;
            try
            {
                /* Lookup the server objcet */
                AuthorServer server = (AuthorServer)Naming.lookup("rmi://192.168.0.52/AuthorServer");

                /* Retreive the details of an author from the Clint frame */
                authorID=textAuthorID.getText();
                lastName=textLastName.getText();
                firstName=textFirstName.getText();
                phone=textPhone.getText();
                address=textAddress.getText();
                city=textCity.getText();
                state=textState.getText();
                zip=textZip.getText();

                /* Invoke the remote method */
                String str=server.insertDetails(authorID, lastName, firstName, phone, address, city, state, zip);
                System.out.println(str);
                if(str.equals("success"))
                {
                    /* Create the object of MyDialog class */
                    myDialog = new MyDialog(frame, "Inserted Successfully");
                }
                else
                {
                    /* Create the object of MyDialog class */
                    myDialog = new  MyDialog(frame, "No Record Inserted");
                }
                myDialog.setVisible(true);
            }
            catch(Exception e)
            {
                System.out.println(e);
            }
        }
    }

    /* Define the main() method */
    public static void main(String args[])
    {
        /* Create the object of the Client class */
        new Client();
    }
}

/* Create the MyDialog class */
class MyDialog extends Dialog implements ActionListener
{
    /* Define the default constructor of the MyDialog class */
    MyDialog(Frame parent, String title)
    {
        super(parent, title, false);
        setLayout(new FlowLayout());
        setSize(200, 80);
        add(new JLabel (title));
        JButton btn_OK  = new JButton("OK");
        add(btn_OK);
        btn_OK.addActionListener(this);
    }
    /* Define the actionPerformed() method */
    public void actionPerformed(ActionEvent ae)
    {
        dispose();
    }
}

thanks plz. check it out compilation is ok means i am getting class file, but no output after getting registered it gives socket error

lakshay,
Use code tags. Source code must be surrounded with code tags.
For example,

[CODE=Java] ... statements..

[/code]
How to post source code?

Member Avatar for ede

Merhaba | Hello,

if you sent what the socket error actually was, it would be clear to identify the error.

But it might originate from java security policy. Please control your java security policy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.