Created
July 26, 2018 15:45
-
-
Save Thomascountz/3872c37d94d3f3f090aadc41010c0869 to your computer and use it in GitHub Desktop.
Simple Echoing Server in Java
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.*; | |
import java.net.*; | |
public class Server { | |
public static void main(String[] args) throws IOException { | |
int port = 5000; | |
ServerSocket serverSocket = new ServerSocket(port); | |
System.out.println("Listening on port " + port); | |
Socket clientSocket = serverSocket.accept(); | |
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | |
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); | |
while (true) { | |
String line = in.readLine(); | |
out.println(line); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment