Server: CODE: Select All package Socket;import java.io.IOException;import java.net.*;import java.util.Scanner;import java.io.*;import java.net.Socket;import java.util.logging.Level;import java.util.logging.Logger;public class Server { public static void main(String[]ds) { try{ ServerSocket svsocket = new ServerSocket(1234); Socket socket = svsocket.accept(); System.out.print("đã kết nối với client"); final BufferedReader read = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter write = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); Thread T_read = new Thread(new Runnable() { @Override public void run (){ while(true) try{ String mes ; mes= read.readLine(); if (mes!=null&& !mes.isEmpty()) { System.out.println(mes); } }catch (IOException ex) { System.out.println(ex); } } }); T_read.start(); while(true){ System.out.println("cnttqn.com"); String mes=new Scanner(System.in).nextLine(); write.write(mes); write.newLine(); write.flush(); }} catch(IOException ex) { System.out.println(ex); } }} Client: CODE: Select All package Socket;import java.io.IOException;import java.net.*;import java.util.Scanner;import java.io.*;import java.net.Socket;import java.util.logging.Level;import java.util.logging.Logger;public class client { public static void main(String[]ds){ try { Socket socket = new Socket("localhost",1234); final BufferedReader read = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter write = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); Thread T_read = new Thread(new Runnable() { @Override public void run (){ while(true) try{ String mes ; mes= read.readLine(); if (mes!=null&& !mes.isEmpty()) { System.out.println(mes); } }catch (IOException ex) { System.out.println(ex); } } }); T_read.start(); while(true){ System.out.println("cntt"); String mes=new Scanner(System.in).nextLine(); write.write(mes); write.newLine(); write.flush(); }} catch(IOException ex){ System.out.print(ex); } }} Hướng dẫn chi tiết bằng Video