write a program to implement the connection oriented echo client server application

Solutions on MaxInterview for write a program to implement the connection oriented echo client server application by the best coders in the world

showing results for - "write a program to implement the connection oriented echo client server application "
Jaylen
11 Sep 2020
1//Client
2import java.io.*;
3import java.net.*;
4
5public class Client {
6    public static void main(String[] args) {
7        try {
8            Socket s = new Socket("localhost", 1234);
9            DataOutputStream dout = new DataOutputStream(s.getOutputStream());
10            dout.writeUTF("Hello Server");
11            dout.flush();
12            dout.close();
13            s.close();
14        } catch (Exception e) {
15            System.out.println(e);
16        }
17    }
18}
19
20//Server
21import java.io.*;
22import java.net.*;
23
24public class Server {
25    public static void main(String[] args) {
26        try {
27            ServerSocket ss = new ServerSocket(1234);
28            Socket s = ss.accept();
29            DataInputStream dis = new DataInputStream(s.getInputStream());
30            String str = (String) dis.readUTF();
31            System.out.println("message= " + str);
32            ss.close();
33        } catch (Exception e) {
34            System.out.println(e);
35        }
36    }
37}