Use Socket to read and write stream
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
class SquareClient {
private final static int BUFSIZE = 20;
public static void main(String args[]) throws Exception {
String server = args[0];
int port = Integer.parseInt(args[1]);
double value = Double.valueOf(args[2]).doubleValue();
Socket s = new Socket(server, port);
OutputStream os = s.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
dos.writeDouble(value);
InputStream is = s.getInputStream();
DataInputStream dis = new DataInputStream(is);
value = dis.readDouble();
System.out.println(value);
s.close();
}
}
Related examples in the same category