I am trying to communicate client and server in one project where my client and server both started in main()
of my project having two different threads but when client try to call the answer_is function of server side it will show the below exception. When I run the client and server combined in one project I got the error
xception in thread "Thread-2" java.lang.InstantiationError: org.apache.xmlrpc.XmlRpcRequest at org.apache.xmlrpc.XmlRpcRequestProcessor.decodeRequest(XmlRpcRequestProcessor.java:82) at org.apache.xmlrpc.XmlRpcWorker.execute(XmlRpcWorker.java:143) at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:139) at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:125) at org.apache.xmlrpc.WebServer$Connection.run(WebServer.java:761) at org.apache.xmlrpc.WebServer$Runner.run(WebServer.java:642) at java.lang.Thread.run(Thread.java:745) Exception in thread "Thread-3" java.lang.InstantiationError: org.apache.xmlrpc.XmlRpcRequest at org.apache.xmlrpc.XmlRpcRequestProcessor.decodeRequest(XmlRpcRequestProcessor.java:82) at org.apache.xmlrpc.XmlRpcWorker.execute(XmlRpcWorker.java:143) at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:139) at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:125) at org.apache.xmlrpc.WebServer$Connection.run(WebServer.java:761) at org.apache.xmlrpc.WebServer$Runner.run(WebServer.java:642) at java.lang.Thread.run(Thread.java:745) JavaClient: org.apache.xmlrpc.XmlRpcException: Failed to create input stream: Unexpected end of file from server
Here is my code for Project 1 having client and server
Main Class
package serverclienttest;
/**
*
* @author root
*/
public class ServerclientTest {
/**
* @param args the 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 as answer_is");
}
public Integer sum(int x, int y){
return new Integer(x+y);
}
public void run()
{
try {
System.out.println("Attempting to 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 to stop.)");
}
catch (Exception exception){
System.err.println("JavaServer: " + exception);
}
}
But when i wrote server side in another project and run it , it will work fine so plz tell me why client and server not run in same project
"Unexpected end of file from Server" implies that the server accepted and closed the connection without sending a response. It's possible that the system is too busy to handle the request, or that there's a bug that randomly drops connections.
In your
ServerclientTest
class, you are invoking:ServerThread serverthread = new ServerThread(); Thread t = new Thread(serverthread);
without implementing
Runnable
. Try changing the class signature as below:public class ServerThread implements Runnable