PROGRAM
import java.io.*; import java.net.*; class tcpser { public static void main(String arg[]) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ServerSocket ob=new ServerSocket(95); Socket obj=ob.accept(); OutputStream op=obj.getOutputStream(); System.out.println("Enter a string (x to exit)"); String str; do { str=br.readLine(); op.write(str.getBytes()); }while(!str.equals("x")); op.close(); obj.close(); } catch(Exception ex) { } } } import java.io.*; import java.net.*; class tcpcl { public static void main(String arg[]) { try { Socket ob=new Socket("localhost",95); InputStream ip=ob.getInputStream(); String t; do { byte b[]=new byte[ip.available()]; ip.read(b); t=new String(b); System.out.println(t); }while(!t.equals("x")); ip.close(); ob.close(); } catch(Exception ex) { } } } |
OUTPUT
Enter a string (x to exit)
Are U there?
Hai..Listen to me
x
Are U there?
Hai..Listen to me
x
Leave a Reply