Sunday, 15 April 2012

Java RMI Error : Connection Reset -



Java RMI Error : Connection Reset -

i've written 3 rmi servers send info each other using udp unicast. every time method executed on particular instance of server initiated server sends requests other servers respond result of method executed on particular instance of server. i've implemented them using threads. method executes first time when execute 1 time again next error:

java.rmi.unmarshalexception: error unmarshaling homecoming header; nested exception is: java.net.socketexception: connection reset @ sun.rmi.transport.streamremotecall.executecall(unknown source) @ sun.rmi.server.unicastref.invoke(unknown source) @ java.rmi.server.remoteobjectinvocationhandler.invokeremotemethod(unknown source) @ java.rmi.server.remoteobjectinvocationhandler.invoke(unknown source) @ com.sun.proxy.$proxy0.getnonreturners(unknown source) @ drms.org.client.drmsclient.main(drmsclient.java:379) caused by: java.net.socketexception: connection reset @ java.net.socketinputstream.read(unknown source) @ java.net.socketinputstream.read(unknown source) @ java.io.bufferedinputstream.fill(unknown source) @ java.io.bufferedinputstream.read(unknown source) @ java.io.datainputstream.readbyte(unknown source) ... 6 more

getnonreturners-method threads created udp communication

requestdata: send request message other servers

responsedata: send response message server requests it

server side code:

public class drmsserver implements drmsinterface, serializable { final static int _concordiaportnumber = 1098; final static int _mcgillportnumber = 222; final static int _dawsonportnumber = 223; /** * description: sends udp request invoked server other servers * * @param: port number * @param: info */ public string requestdata(final int portnumber, final string data) { stringbuilder sb = new stringbuilder(); seek { final datagramsocket clientsocket = new datagramsocket(); final byte[] receivedata = new byte[1024000]; final datagrampacket receivepacket = new datagrampacket( receivedata, receivedata.length); byte[] senddata = new byte[1024000]; senddata = data.getbytes(); system.out.print("ready send info "); sb.append("ready send info "); sb.append("\n"); final datagrampacket sendpacket = new datagrampacket(senddata, senddata.length, ipaddress, portnumber); clientsocket.send(sendpacket); clientsocket.setsotimeout(10000); seek { clientsocket.receive(receivepacket); final string _result = new string(receivepacket.getdata()); final inetaddress returnipaddress = receivepacket.getaddress(); final int port = receivepacket.getport(); system.out.println("from server at: " + returnipaddress + ":" + port); sb.append("from server at: " + returnipaddress + ":" + port); sb.append("\n"); system.out.println("message: " + _result); sb.append("message: " + _result); } grab (final sockettimeoutexception ste) { system.out.println("timeout occurred: packet assumed lost"); } // clientsocket.close(); } grab (final socketexception e) { e.printstacktrace(); } grab (final ioexception e) { e.printstacktrace(); } homecoming sb.tostring(); } /** * description: returns administrator list of defaulter * have book past loan date. based on udp request * invoked server sends udp response. * * @param: port number */ public string responsedata(final int portnumber) throws notboundexception { string _result = null; seek { @suppresswarnings("resource") final datagramsocket serversocket = new datagramsocket(portnumber, ipaddress); final drmsinterface _concordiaserver = (drmsinterface) naming .lookup("rmi://localhost:1098/concordia"); final drmsinterface _mcgillserver = (drmsinterface) naming .lookup("rmi://localhost:222/mcgill"); final drmsinterface _dawsonserver = (drmsinterface) naming .lookup("rmi://localhost:223/dawson"); byte[] receivedata = new byte[1024000]; byte[] senddata = new byte[1024000]; string regex = "(?<=[\\w&&\\d])(?=\\d)"; while (true) { receivedata = new byte[1024000]; final datagrampacket receivepacket = new datagrampacket( receivedata, receivedata.length); system.out.println("waiting datagram packet"); serversocket.receive(receivepacket); final string _request = new string(receivepacket.getdata()); system.out.println(_request); string array[] = _request.split(regex); string _educationalinstitution = array[0]; system.out.println(_educationalinstitution); int numdays = integer.parseint(array[1].trim()); system.out.println(numdays); final inetaddress ipaddress = receivepacket.getaddress(); final int port = receivepacket.getport(); system.out.println("from: " + ipaddress + ":" + port); system.out.println("request message from: " + _request.touppercase()); if (_educationalinstitution.tolowercase().equals("concordia")) { if (portnumber == _mcgillportnumber) { _result = _mcgillserver.getnonreturnersdata( _educationalinstitution, numdays); } else if (portnumber == _dawsonportnumber) { _result = _dawsonserver.getnonreturnersdata( _educationalinstitution, numdays); } } else if (_educationalinstitution.tolowercase().equals("mcgill")) { if (portnumber == _concordiaportnumber) { _result = _concordiaserver.getnonreturnersdata( _educationalinstitution, numdays); } else if (portnumber == _dawsonportnumber) { _result = _dawsonserver.getnonreturnersdata( _educationalinstitution, numdays); } } else if (_educationalinstitution.tolowercase().equals("dawson")) { if (portnumber == _mcgillportnumber) { _result = _mcgillserver.getnonreturnersdata( _educationalinstitution, numdays); } else if (portnumber == _dawsonportnumber) { _result = _dawsonserver.getnonreturnersdata( _educationalinstitution, numdays); } } // final string capitalizedsentence = if(_result !=null){ senddata = _result.getbytes(); } else{ _result="no defaulters"; senddata = _result.getbytes(); } final datagrampacket sendpacket = new datagrampacket(senddata, senddata.length, ipaddress, port); serversocket.send(sendpacket); } } grab (final socketexception ex) { system.out.println("udp port 9876 occupied."); system.exit(1); } grab (final ioexception e) { e.printstacktrace(); } homecoming _result; } /** * description: returns administrator list of defaulter * have book past loan date * * @param: admin username * @param: admin password * @param: educational establishment * @param: no of days */ public string getnonreturnersdata(string educationalinstituion, int numdays) { //returns info } /** * description: using method admin invoked server communicates * other servers using udp/ip messages information.once * info received admin invoked server sends result string * admin * * @param: admin username * @param: admin password * @param: educational establishment * @param: no of days */ @override public string getnonreturners(string adminusername, string adminpassword, string educationalinstitution, int numdays) throws remoteexception, exception { string _result = null; string _initiatedserverresult=null; final arraylist<string> result = new arraylist<string>(); final drmsinterface _concordiaserver = (drmsinterface) naming .lookup("rmi://localhost:1098/concordia"); final drmsinterface _mcgillserver = (drmsinterface) naming .lookup("rmi://localhost:222/mcgill"); final drmsinterface _dawsonserver = (drmsinterface) naming .lookup("rmi://localhost:223/dawson"); if (educationalinstitution.tolowercase().equals("concordia")) { final thread t1 = new thread() { @override public void run() { seek { result.add(_mcgillserver .responsedata(_mcgillportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t1.setdaemon(true); t1.start(); final thread t2 = new thread() { @override public void run() { seek { result.add(_dawsonserver .responsedata(_dawsonportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t2.setdaemon(true); t2.start(); system.out.println("attemping connect " + ipaddress + ") via udp port" + _mcgillportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _mcgillportnumber); result.add("/n"); system.out.println("attemping connect " + ipaddress + ") via udp port" + _dawsonportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _dawsonportnumber); result.add("/n"); final string _concordiarequestmessage = educationalinstitution + numdays; system.out.println("sending info " + _concordiarequestmessage.length() + " bytes server."); result.add("sending info " + _concordiarequestmessage.length() + " bytes server."); result.add(_concordiaserver.requestdata(_mcgillportnumber, _concordiarequestmessage)); result.add(_concordiaserver.requestdata(_dawsonportnumber, _concordiarequestmessage)); _initiatedserverresult=_concordiaserver.getnonreturnersdata( educationalinstitution, numdays); if(_initiatedserverresult !=null){ result.add(_initiatedserverresult); } else{ result.add("no defaulters in concordia"); } } else if (educationalinstitution.tolowercase().equals("mcgill")) { final thread t1 = new thread() { @override public void run() { seek { result.add(_concordiaserver .responsedata(_concordiaportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t1.setdaemon(true); t1.start(); final thread t2 = new thread() { @override public void run() { seek { result.add(_dawsonserver .responsedata(_dawsonportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t2.setdaemon(true); t2.start(); system.out.println("attemping connect " + ipaddress + ") via udp port" + _concordiaportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _concordiaportnumber); system.out.println("attemping connect " + ipaddress + ") via udp port" + _dawsonportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _dawsonportnumber); final string _mcgillrequestmessage = educationalinstitution + numdays; system.out.println("sending info " + _mcgillrequestmessage.length() + " bytes server."); result.add("sending info " + _mcgillrequestmessage.length() + " bytes server."); result.add(_mcgillserver.requestdata(_concordiaportnumber, _mcgillrequestmessage)); result.add(_mcgillserver.requestdata(_dawsonportnumber, _mcgillrequestmessage)); _initiatedserverresult=_mcgillserver.getnonreturnersdata( educationalinstitution, numdays); if(_initiatedserverresult !=null) { result.add(_initiatedserverresult); } else{ result.add("no defaulters in mcgill"); } } else if (educationalinstitution.tolowercase().equals("dawson")) { final thread t1 = new thread() { @override public void run() { seek { result.add(_concordiaserver .responsedata(_concordiaportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t1.setdaemon(true); t1.start(); final thread t2 = new thread() { @override public void run() { seek { result.add(_mcgillserver .responsedata(_mcgillportnumber)); } grab (remoteexception | notboundexception e) { e.printstacktrace(); } } }; t2.setdaemon(true); t2.start(); system.out.println("attemping connect " + ipaddress + ") via udp port" + _concordiaportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _concordiaportnumber); system.out.println("attemping connect " + ipaddress + ") via udp port" + _mcgillportnumber); result.add("attemping connect " + ipaddress + ") via udp port" + _mcgillportnumber); final string _dawsonrequestmessage = educationalinstitution + numdays; system.out.println("sending info " + _dawsonrequestmessage.length() + " bytes server."); result.add("sending info " + _dawsonrequestmessage.length() + " bytes server."); result.add(_dawsonserver.requestdata(_concordiaportnumber, _dawsonrequestmessage)); result.add(_dawsonserver.requestdata(_mcgillportnumber, _dawsonrequestmessage)); result.add(_concordiaserver.getnonreturnersdata( educationalinstitution, numdays)); _initiatedserverresult=_dawsonserver.getnonreturnersdata( educationalinstitution, numdays); if(_initiatedserverresult !=null) { result.add(_initiatedserverresult); } else{ result.add("no defaulters in dawson"); } } homecoming _result = result.tostring(); } /** * description: creates remote concordia server object * did same other 2 servers */ public void exportserverconcordia() throws exception { remote _obj = unicastremoteobject.exportobject(this, _concordiaportnumber); registry _r = locateregistry.createregistry(_concordiaportnumber); _r.bind("concordia", _obj); } public static void main(string args[]) { seek { drmsserver concordia = new drmsserver(); concordia.exportserverconcordia(); system.out.println("concordia server , running"); drmsserver mcgill = new drmsserver(); mcgill.exportservermcgill(); system.out.println("mcgill server , running"); drmsserver dawson = new drmsserver(); dawson.exportserverdawson(); system.out.println("dawson server , running"); //tried 1 solution didn't work seek { while (true){ try{ thread.currentthread(); thread.sleep (50000000l); }catch (interruptedexception e) {} } } grab (exception ex) { system.err.println("exiting frequency keeper server"); ex.printstacktrace(); } } grab (exception e) { e.printstacktrace(); } }

i line executed:

system.exit(1);

java rmi

No comments:

Post a Comment