Source Code : Read and write with ServerSocket
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Read and write with ServerSocket
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
class SquareServer {
private final static int BUFSIZE = 20;
public static void main(String args[]) throws Exception {
int port = Integer.parseInt(args[0]);
ServerSocket ss = new ServerSocket(port);
while (true) {
Socket s = ss.accept();
InputStream is = s.getInputStream();
DataInputStream dis = new DataInputStream(is);
double value = dis.readDouble();
value *= value;
OutputStream os = s.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
dos.writeDouble(value);
s.close();
}
}
}
Thank with us