public class Chat_Client { public static void client () { try { Socket cs = new Socket("localhost", 9); PrintStream cp = new PrintStream(cs.getOutputStream()); System.out.print("Client: "); InputStreamReader cir = new InputStreamReader(System.in); BufferedReader cbr = new BufferedReader(cir); String temp1 = cbr.readLine(); cp.println(temp1); BufferedReader cbr1 = new BufferedReader(new InputStreamReader(cs.getInputStream())); String temp2 = cbr1.readLine(); System.out.print(temp2); } catch(Exception e) { } } public static void main(String[] args) { client(); }
public class Chat_server1 { public static void server() { try { ServerSocket ss = new ServerSocket(9); Socket cs = ss.accept(); BufferedReader cbr = new BufferedReader(new InputStreamReader(cs.getInputStream())); String temp = cbr.readLine(); System.out.print("Client :" +temp); //JOptionPane.showMessageDialog(null,"Salam"); PrintStream spr = new PrintStream(cs.getOutputStream()); String temp1 = "Server: I got your message "; spr.println(temp1); //server(); } catch(Exception e) { } } public static void main(String[] args) { // TODO code application logic here server(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)