Merged race scaling with Http Match Discovery.
This commit is contained in:
@@ -15,6 +15,9 @@ import java.io.IOException;
|
||||
public class HttpMatchBrowserClient extends Thread {
|
||||
public ObservableList<RaceConnection> connections = FXCollections.observableArrayList();
|
||||
|
||||
/**
|
||||
* Get all the matches that have been running in the past 5 seconds.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while(!Thread.interrupted()) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 19/09/2017.
|
||||
* Creates an Http connection that hosts a game
|
||||
*/
|
||||
public class HttpMatchBrowserHost extends Thread {
|
||||
private HttpClient httpClient;
|
||||
@@ -25,6 +25,12 @@ public class HttpMatchBrowserHost extends Thread {
|
||||
|
||||
public static HttpMatchBrowserHost httpMatchBrowserHost = null;
|
||||
|
||||
/**
|
||||
* Constructor, this sends out the creation message of the race.
|
||||
* the thread should be run as soon as possible as the race is only valid for 5 seconds
|
||||
* until it requires a heartbeat from the start function.
|
||||
* @throws IOException if the hosting url is unreachable.
|
||||
*/
|
||||
public HttpMatchBrowserHost() throws IOException {
|
||||
httpMatchBrowserHost = this;
|
||||
httpClient = HttpClients.createDefault();
|
||||
@@ -38,6 +44,11 @@ public class HttpMatchBrowserHost extends Thread {
|
||||
System.out.println("Register Match");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a post to a server.
|
||||
* @param domain url of to send to
|
||||
* @throws IOException if the url is unreachable.
|
||||
*/
|
||||
public void sendHttp(String domain) throws IOException {
|
||||
HttpPost httppost = new HttpPost(domain);
|
||||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
@@ -58,6 +69,9 @@ public class HttpMatchBrowserHost extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* THe host starts sending out heartbeat messages every 2 seconds.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while(!Thread.interrupted()){
|
||||
|
||||
Reference in New Issue
Block a user