Professional Documents
Culture Documents
SERVER:
import java.net.*;
import java.io.*;
import java.util.*;
public class MyServer4
{
public static void main(String args[])
{
try
{
ServerSocket ss=new ServerSocket(6666);//socket port
Socket s=ss.accept();//it will accept and return the socket
DataInputStream dis=new
DataInputStream(s.getInputStream());//for receiving we use
datainputstream
int n1=dis.readInt();//here read function will return something so we
are storing that in the variable
int n2=dis.readInt();
int result=n1+n2;
System.out.println("result of the addition is "+result);
DataOutputStream out=new
DataOutputStream(s.getOutputStream());
out.writeInt(result);
System.out.println("sent the result to the client");
ss.close();
}
catch(Exception e)
{
System.out.println("message not received and server is busy");
}
}
}