OPERATING SYSTEM (PRACTICAL-2 (in java))


 

PRACTICAL-2 


Server and client socket program in java


Server socket program :


import java.io.*;  

import java.net.*;  

public class Server {  

public static void main(String[] args){  

try{  

ServerSocket ss=new ServerSocket(6666);  

Socket s=ss.accept();//establishes connection   

DataInputStream dis=new DataInputStream(s.getInputStream());  

String  str=(String)dis.readUTF();  

System.out.println("My Name is = "+str);  

ss.close();  

}catch(Exception e){System.out.println(e);}  

}  






client socket program :


import java.io.*;  

import java.net.*;  

public class Client {  

public static void main(String[] args) {  

try{      

Socket s=new Socket("localhost",6666);  

DataOutputStream dout=new DataOutputStream(s.getOutputStream());  

dout.writeUTF("Ramiz Belim");  

dout.flush();  

dout.close();  

s.close();  

}catch(Exception e){System.out.println(e);}  

}  

}  


Result :

 

Compile - > gcc server.java -o server

gcc client.java -o client

Run - > ./server

./client




 



Download doc file here.....






Download pdf here.....

No comments:

Post a Comment