-
-
Save seyedsahil/c18ecb901d65000a9844821aba3041f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.*; | |
import java.util.Date; | |
/** | |
* @author Seyed Sahil | |
*/ | |
public class App { | |
public static void main(String[] args) throws IOException { | |
ServerSocket serverSocket = new ServerSocket(8080); | |
System.out.println("Server session started at " + new Date()); | |
int connections = 0; | |
while (connections != 2) { | |
System.out.println("Server is listening on port 8080"); | |
Socket clientSocket = serverSocket.accept(); | |
connections++; | |
System.out.println("Server connected with Client-" + connections + " at " + new Date()); | |
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); | |
out.println("Hello Client-" + connections + ", What is your name ?"); | |
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | |
out.println("Hey " + in.readLine() + ", Nice to meet you!"); | |
in.close(); | |
out.close(); | |
clientSocket.close(); | |
} | |
serverSocket.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment