Search

java socket (Client part)

import java.net.*;
import java.io.*;
public class client{
 public static void main(String a[]){
 try{
  Socket w=new Socket("localhost",1234);
  DataOutputStream o=new DataOutputStream(w.getOutputStream());
  o.writeUTF("where are you");
  DataInputStream i=new DataInputStream(w.getInputStream());
  String sr=new String(i.readUTF());
  System.out.println(sr);
  o.close();
  i.close();
  w.close();
 }
 catch(UnknownHostException u){
 System.out.println("message"+u);
 }
 catch(IOException i){
 System.out.println("message"+i);
 }
}

}

No comments:

Post a Comment

Java Interfaces vs. Abstract class

Summary of the similarities and differences between the Interfaces and Abstract class Abstract class Interface Has a constructor Yes No An i...