ClientA.java 1 2 import java.io.

IOException; 9 10 public class ClientA { 11 public static void main(String[] args) { 12 try { 13 // 14 // tao connection toi server 15 // 16 InetAddress host = InetAddress.getLocalHost(); 17 Socket socket = new Socket(host.getHostName(), 7777); 18 19 // 20 // gui message toi server 21 // 22 ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); 23 oos.writeObject("Hello There..."); 24 25 // 26 // Doc va hien thi message gui tu server toi 27 // 28 ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); 29 String message = (String) ois.readObject(); 30 System.out.println("Message: " + message); 31 32 ois.close(); 33 oos.close(); 34 } catch (UnknownHostException e) { 35 e.printStackTrace(); 36 } catch (IOException e) { 37 e.printStackTrace(); 38 } catch (ClassNotFoundException e) { 39 e.printStackTrace(); 40 } 41 } 42 } 43 44 45

Page 1

Sign up to vote on this title
UsefulNot useful