Improved Backend
This commit is contained in:
64
QuickLaunchUpdateServer/src/network/ServerThread.java
Normal file
64
QuickLaunchUpdateServer/src/network/ServerThread.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user