├── .gitignore ├── .idea ├── .gitignore ├── misc.xml ├── modules.xml └── vcs.xml ├── Client ├── .gitignore ├── Client.iml └── src │ └── Client.java ├── Server ├── .gitignore ├── Server.iml └── src │ └── Server.java └── SocketProgramming.iml /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Client/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Client/Client.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Client/src/Client.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.Socket; 3 | 4 | public class Client { 5 | public static void main(String[] args) { 6 | try (Socket socket = new Socket("localhost", 1)){ 7 | 8 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 9 | DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream()); 10 | DataInputStream dataInputStream = new DataInputStream(socket.getInputStream()); 11 | 12 | String msg = ""; 13 | String rly; 14 | 15 | while (!msg.equals("bye")) { 16 | System.out.print("Client : "); 17 | msg = bufferedReader.readLine(); 18 | dataOutputStream.writeUTF(msg); 19 | dataOutputStream.flush(); 20 | 21 | rly = dataInputStream.readUTF(); 22 | System.out.println("Server : " + rly); 23 | } 24 | 25 | dataInputStream.close(); 26 | dataOutputStream.close(); 27 | bufferedReader.close(); 28 | 29 | } catch (IOException e) { 30 | throw new RuntimeException(e); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Server/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Server/Server.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Server/src/Server.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.ServerSocket; 3 | import java.net.Socket; 4 | 5 | public class Server { 6 | public static void main(String[] args) { 7 | try (ServerSocket serverSocket = new ServerSocket(1)){ 8 | System.out.println("Server is listening for clients ..... "); 9 | Socket socket = serverSocket.accept(); 10 | System.out.println("Client is connected!"); 11 | 12 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 13 | DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream()); 14 | DataInputStream dataInputStream = new DataInputStream(socket.getInputStream()); 15 | 16 | String msg = ""; 17 | String rly; 18 | 19 | while (!msg.equals("bye")) { 20 | rly = dataInputStream.readUTF(); 21 | System.out.println("Client : " + rly); 22 | 23 | System.out.print("Server : "); 24 | msg = bufferedReader.readLine(); 25 | dataOutputStream.writeUTF(msg); 26 | dataOutputStream.flush(); 27 | } 28 | 29 | dataInputStream.close(); 30 | dataOutputStream.close(); 31 | bufferedReader.close(); 32 | socket.close(); 33 | 34 | } catch (IOException e) { 35 | throw new RuntimeException(e); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SocketProgramming.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------