c++ - Java XML RPC Client and server -
i trying communicate client , server in 1 project client , server both started in main()
of project having 2 different threads when client try call answer_is function of server side show below exception. when run client , server combined in 1 project got error
xception in thread "thread-2" java.lang.instantiationerror: org.apache.xmlrpc.xmlrpcrequest @ org.apache.xmlrpc.xmlrpcrequestprocessor.decoderequest(xmlrpcrequestprocessor.java:82) @ org.apache.xmlrpc.xmlrpcworker.execute(xmlrpcworker.java:143) @ org.apache.xmlrpc.xmlrpcserver.execute(xmlrpcserver.java:139) @ org.apache.xmlrpc.xmlrpcserver.execute(xmlrpcserver.java:125) @ org.apache.xmlrpc.webserver$connection.run(webserver.java:761) @ org.apache.xmlrpc.webserver$runner.run(webserver.java:642) @ java.lang.thread.run(thread.java:745) exception in thread "thread-3" java.lang.instantiationerror: org.apache.xmlrpc.xmlrpcrequest @ org.apache.xmlrpc.xmlrpcrequestprocessor.decoderequest(xmlrpcrequestprocessor.java:82) @ org.apache.xmlrpc.xmlrpcworker.execute(xmlrpcworker.java:143) @ org.apache.xmlrpc.xmlrpcserver.execute(xmlrpcserver.java:139) @ org.apache.xmlrpc.xmlrpcserver.execute(xmlrpcserver.java:125) @ org.apache.xmlrpc.webserver$connection.run(webserver.java:761) @ org.apache.xmlrpc.webserver$runner.run(webserver.java:642) @ java.lang.thread.run(thread.java:745) javaclient: org.apache.xmlrpc.xmlrpcexception: failed create input stream: unexpected end of file server
here code project 1 having client , server
main class
package serverclienttest; /** * * @author root */ public class serverclienttest { /** * @param args command line arguments */ public static void main(string[] args) { // todo code application logic here try { serverthread serverthread = new serverthread(); thread t = new thread(serverthread); t.start(); clientthread clientthread = new clientthread(); thread t1 = new thread(clientthread); t1.start(); } catch (exception exception) { system.err.println("webclientserver: " + exception); } } }
clientside
package serverclienttest; import java.net.url; import java.util.map; import java.util.scanner; import java.util.vector; import java.util.*; import java.io.*; import java.net.*; import org.apache.xmlrpc.client.xmlrpcclientconfigimpl; import org.apache.xmlrpc.client.xmlrpcclient; import java.util.*; import java.io.*; /** * * @author root */ public class clientthread implements runnable{ public void run() { try { // xmlrpcclient server = new xmlrpcclient("http://localhost/rpc2"); xmlrpcclient client = new xmlrpcclient(); xmlrpcclientconfigimpl config = new xmlrpcclientconfigimpl(); config.setserverurl(new url("http://localhost:5300/rpc2")); config.setenabledforextensions(true); //vector params = new vector(); /* hashtable params = new hashtable(); params.put(1, 1); params.put(2, 2);*/ object[] testclass = new object[]{1,2}; client.setconfig(config); int result = (integer) client.execute("sample.sum", testclass); system.out.print("client executed"); int sum = ((integer) result).intvalue(); system.out.println("the sum is: "+ sum); } catch (exception exception) { system.err.println("javaclient: " + exception); } } }
server side
public class serverthread { public serverthread() { system.out.println("handler registered answer_is"); } public integer sum(int x, int y){ return new integer(x+y); } public void run() { try { system.out.println("attempting start xml-rpc server..."); webserver server = new webserver(5300); server.addhandler("sample", new serverthread()); server.start(); system.out.println("started successfully."); system.out.println("accepting requests. (halt program stop.)"); } catch (exception exception){ system.err.println("javaserver: " + exception); } }
but when wrote server side in project , run , work fine plz tell me why client , server not run in same project
"unexpected end of file server" implies server accepted , closed connection without sending response. it's possible system busy handle request, or there's bug randomly drops connections.
in serverclienttest
class, invoking: serverthread serverthread = new serverthread(); thread t = new thread(serverthread);
without implementing runnable
. try changing class signature below:
public class serverthread implements runnable
Comments
Post a Comment