Skip to content

Instantly share code, notes, and snippets.

@StefanKruk
Last active December 23, 2015 23:59
Show Gist options
  • Select an option

  • Save StefanKruk/6713929 to your computer and use it in GitHub Desktop.

Select an option

Save StefanKruk/6713929 to your computer and use it in GitHub Desktop.
A Simple Java Programm that open a ServerSocket and asking for a number. "\u001B[31m" make the Text Red "\u001B[37m" make the Text White
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Test
{
final static String SCREEN_CLR = "\u001B[2J";
final static String SCREEN_REP = "\u001B[1;1H";
public static void main(String[] args) throws Exception
{
String text = "";
ServerSocket s = new ServerSocket(23);
Socket server = s.accept();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(server.getInputStream()));
while (!text.equals("stop"))
{
/* CLEAR the Console
out.write("Bitte zahl eingeben: ");
out.flush();
text = in.readLine();
System.out.println(text);
out.write(SCREEN_CLR);
out.flush();
out.write(SCREEN_REP);
out.flush();
*/
// Print the Number you send in Red in the Console
out.write("Bitte zahl eingeben: ");
out.flush();
text = in.readLine();
out.newLine();
out.write("\u001B[31m" + text + "\u001B[37m\n");
out.flush();
out.newLine();
}
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment