Improved Backend

This commit is contained in:
2019-04-28 11:19:53 +02:00
parent c4ed32689d
commit 02e63e14c0
29 changed files with 175 additions and 42 deletions

View File

@@ -0,0 +1,64 @@
package network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import scenes.LogScene;
public class ServerThread
implements Runnable {
private final int PORT = 9999;
public static float version = -1.0f;
LogScene display;
public ServerThread(LogScene scene) {
display = scene;
}
ServerSocket ses;
Socket s;
DataOutputStream out;
DataInputStream in;
public void run() {
do {
try {
do {
ses = new ServerSocket(this.PORT);
s = ses.accept();
System.out.println("Connected with: " + s.getInetAddress());
out = new DataOutputStream(s.getOutputStream());
in = new DataInputStream(s.getInputStream());
String data = in.readUTF();
display.appendText(data);
System.out.println(data);
out.writeUTF("VERSION="+version);
out.close();
in.close();
s.close();
ses.close();
} while (true);
}
catch (IOException io) {
io.printStackTrace();
try {
out.close();
in.close();
s.close();
ses.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("Server panic");
}
}
} while (true);
}
}