tcp server raw implementation
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
package org.lumijiez;
|
||||
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
import org.lumijiez.core.TcpServer;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.printf("Hello and welcome!");
|
||||
TcpServer server = new TcpServer(8080, (message, clientSocket) -> {
|
||||
System.out.println("Processing message from " + clientSocket.getInetAddress() + ": " + message);
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
System.out.println("i = " + i);
|
||||
if (message.equalsIgnoreCase("hello")) {
|
||||
return "Hello, client!";
|
||||
} else if (message.equalsIgnoreCase("bye")) {
|
||||
return "Goodbye!";
|
||||
} else {
|
||||
return "Unknown command.";
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(server::start).start();
|
||||
|
||||
try {
|
||||
Thread.sleep(60000);
|
||||
server.stop();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user