Fibonacci Client
import java.net.*;
import java.io.*;
public class FibonacciClient {
public static void main(String[] args) {
int port = FibonacciServer.DEFAULT_PORT;
try {
Socket s = new Socket("localhost", port);
Writer out = new OutputStreamWriter(s.getOutputStream(), "ASCII");
out.write("POST /RPC2 HTTP/1.0\r\n");
out.write("Host: betty.userland.com\r\n");
out.write("Content-Type: text/xml\r\n");
out.write("Content-length: 150\r\n");
out.write("\r\n");
out.write("<?xml version=\"1.0\"?>\r\n");
out.write("<methodCall>\r\n");
out.write("<methodName>Fibonacci</methodName>\r\n");
out.write("<params>\r\n");
out.write(" <param>\r\n");
out.write(" <value><int>4</int></value>\r\n");
out.write(" </param>\r\n");
out.write("</params>\r\n");
out.write("</methodCall>\r\n");
out.flush();
InputStream in = s.getInputStream();
s.close();
int c;
while ((c = in.read()) != -1) {
System.out.write(c);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}