java - Unable to connect RMI client to host, unmarshalexception caused by eofexception -
i have following files open in netbeans.
server:
package server; import java.rmi.*; import java.rmi.registry.*; import java.rmi.server.*; import java.sql.*; public class server implements serverinterface { private connection con; private statement st; public server(string db, string username, string password) { try { con = drivermanager.getconnection(db, username, password); st = con.createstatement(); } catch(exception e) { system.out.println(e); } } public static void main(string[] args) { try { server server = new server("jdbc:mysql://localhost:3306/db", "root", "password"); system.setsecuritymanager(new rmisecuritymanager()); serverinterface stub = (serverinterface) unicastremoteobject.exportobject(server, 0); registry registry = locateregistry.createregistry(1099); registry.rebind("server", stub); } catch (exception e) { system.out.println(e); } } public boolean authenticate(string username, string password) { try { string query = "select * staff staff_id ='" + username + "' , password = '" + password + "'"; resultset rs = st.executequery(query); if(rs.next()) { return true; } else { return false; } } catch(exception e) { system.out.println(e); } return false; } }
client:
package client; import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.rmi.registry.*; public class client extends jframe implements actionlistener { jframe main; jpanel loginpanel; jpanel contentpanel; jbutton horse; jbutton staff; jbutton loan; jbutton treatment_record; jbutton work_record; jbutton contact; jbutton loaner; jbutton field_visit; jbutton login; jtextfield username; jpasswordfield password; string usernamestring; string passwordstring; public client() { try { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } catch (exception e) { system.out.println(e); } loginpanel = new jpanel(); contentpanel = new jpanel(); login = new jbutton("login"); username = new jtextfield(20); password = new jpasswordfield(20); horse = new jbutton("horses"); staff = new jbutton("staff"); loan = new jbutton("current loans"); treatment_record = new jbutton("treatment records"); work_record = new jbutton("work records"); contact = new jbutton("contacts"); loaner = new jbutton("loaners"); field_visit = new jbutton("field visits"); horse.addactionlistener(this); staff.addactionlistener(this); loan.addactionlistener(this); treatment_record.addactionlistener(this); work_record.addactionlistener(this); contact.addactionlistener(this); loaner.addactionlistener(this); field_visit.addactionlistener(this); login.addactionlistener(this); loginpanel.add(new jlabel("username")); loginpanel.add(username); loginpanel.add(new jlabel("password")); loginpanel.add(password); loginpanel.add(login); contentpanel.add(horse); contentpanel.add(staff); contentpanel.add(loan); contentpanel.add(treatment_record); contentpanel.add(work_record); contentpanel.add(contact); contentpanel.add(loaner); contentpanel.add(field_visit); contentpanel.setlayout(new gridlayout(0, 3)); loginpanel.setlayout(new gridlayout(0, 2)); contentpanel.setsize(800, 600); this.settitle("trc database"); this.setdefaultcloseoperation(exit_on_close); this.setcontentpane(loginpanel); this.setvisible(true); this.pack(); } public static void main(string[] args) { new client(); try { registry registry = locateregistry.getregistry(); serverinterface stub = (serverinterface) registry.lookup("server"); } catch (exception e) { system.out.println(e); } } public void actionperformed(actionevent ae) { if (ae.getsource() == login) { usernamestring = username.gettext(); passwordstring = password.gettext(); joptionpane.showmessagedialog(null, "button pressed!"); } this.revalidate(); this.pack(); } }
client side stub:
package client; import java.rmi.*; public interface serverinterface extends remote { public boolean authenticate(string username, string password) throws remoteexception; }
server side stub:
package server; import java.rmi.*; public interface serverinterface extends remote { public boolean authenticate(string username, string password) throws remoteexception; }
the server class executes fine, running client class gives following error:
java.rmi.unmarshalexception: error unmarshaling return header; nested exception is: java.io.eofexception
stacktrace:
java.rmi.unmarshalexception: error unmarshaling return header; nested exception is: java.io.eofexception @ sun.rmi.transport.streamremotecall.executecall(streamremotecall.java:227) @ sun.rmi.server.unicastref.invoke(unicastref.java:377) @ sun.rmi.registry.registryimpl_stub.lookup(unknown source) @ client.client.main(client.java:88) caused by: java.io.eofexception @ java.io.datainputstream.readbyte(datainputstream.java:267) @ sun.rmi.transport.streamremotecall.executecall(streamremotecall.java:213) ... 3 more
i've seen lot of people having same error message can't find solutions posted it. can here please me?
this caused sandbox permission problems @ peer. rid of security manager. don't need here.
Comments
Post a Comment