IPC: Sockets: Assignment No 9a Title Objective
IPC: Sockets: Assignment No 9a Title Objective
Assignment No 9a
Program-
Server-
import java.net.*;
import java.io.*;
class uos91server
{
public static void main(String []args)throws Exception
{
ServerSocket ss=new ServerSocket(5050);
System.out.println("Server is Waiting.....");
Socket s=ss.accept();
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
DataInputStream dis=new DataInputStream(s.getInputStream());
String str="Welcomes you are connected \n";
dos.writeUTF(str);
str=dis.readUTF();
System.out.println("From client"+" "+str);
ss.close();
s.close();
dos.close();
dis.close();
}
}
Client-
import java.net.*;
import java.io.*;
class uos91client
{
public static void main(String []args)throws Exception
{
Socket s=new Socket("localhost",5050);
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=dis.readUTF();
System.out.println("From server"+" "+str);
str="Thank u for connecting";
dos.writeUTF(str);
s.close();
dos.close();
dis.close();
}
}
Output-
Conclusion-
Java can be used to establish communication between two programs on remote or
same machine using sockets and system calls.
Reference-
http://www.prasannatech.net/2008/07/socket-programming-tutorial.html