Fixed an issue where buffers aren't being sent properly

Tags #Story[829]
This commit is contained in:
Michael Rausch
2017-04-30 16:16:44 +12:00
parent 9a995ddcc1
commit 1cf55f3e96
10 changed files with 35 additions and 13 deletions
+25 -10
View File
@@ -24,7 +24,7 @@ public class ServerThread implements Runnable, Observer {
private final int RACE_START_STATUS_PERIOD = 1000/2;
private final int BOAT_LOCATION_PERIOD = 1000/5;
private final int PORT_NUMBER = 8085;
private final int TIME_TILL_RACE_START = 10;
private final int TIME_TILL_RACE_START = 20;
private static final int LOG_LEVEL = 1;
public ServerThread(String threadName){
@@ -103,11 +103,22 @@ public class ServerThread implements Runnable, Observer {
raceStatus = RaceStatus.STARTED;
}
else{
raceStatus = RaceStatus.PRESTART;
long currentTime = System.currentTimeMillis()/1000;
long timeDifference = startTime - currentTime;
if (timeDifference > 60*3){
raceStatus = RaceStatus.PRESTART;
}
else if (timeDifference > 60){
raceStatus = RaceStatus.WARNING;
}
else{
raceStatus = RaceStatus.PREPARATORY;
}
}
}
else{
raceStatus = RaceStatus.NOTACTIVE;
raceStatus = RaceStatus.TERMINATED;
}
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.EAST,
@@ -171,21 +182,23 @@ public class ServerThread implements Runnable, Observer {
}, 0, RACE_START_STATUS_PERIOD);
}
/**
* Start sending race start status messages until race starts
*/
private void startSendingRaceStatusMessages(){
serverLog("Sending Race Status Messages", 0);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
Message statusMessage = getRaceStatusMessage();
Message raceStatusMessage = getRaceStatusMessage();
try {
server.send(statusMessage);
server.send(raceStatusMessage);
} catch (IOException e) {
System.out.print("");
}
}
}, 100, RACE_STATUS_PERIOD);
}, 0, RACE_STATUS_PERIOD);
}
/**
@@ -221,16 +234,18 @@ public class ServerThread implements Runnable, Observer {
serverLog("Failed to bind socket: " + e.getMessage(), 0);
}
startTime = (System.currentTimeMillis()/1000) + TIME_TILL_RACE_START;
// Wait for client to connect
server.start();
startTime = (System.currentTimeMillis()/1000) + TIME_TILL_RACE_START;
startSendingHeartbeats();
sendXml();
startSendingRaceStartStatusMessages();
startSendingRaceStatusMessages();
//serverLog("Sending Race Status Messages", 0);
}
/**
@@ -54,6 +54,7 @@ class StreamingServerSocket {
//System.out.println(client);
message.send(client);
seqNum++;
}
@@ -135,7 +135,7 @@ public class BoatLocationMessage extends Message {
heading = (heading + 180.0) % 360.0;
long headingToSend = (long)((heading/360.0)*65535.0);
long headingToSend = (long)((heading/360.0)*49152.0);
putByte((byte) messageVersionNumber);
putInt(time, 6);
@@ -35,6 +35,7 @@ public class Heartbeat extends Message {
putUnsignedInt(seqNo, 4);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
@@ -55,6 +55,7 @@ public class MarkRoundingMessage extends Message{
putByte((byte) markId);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
@@ -9,7 +9,7 @@ public enum MessageType {
RACE_STATUS(12),
DISPLAY_TEXT_MESSAGE(20),
XML_MESSAGE(26),
RACE_START_STATUS(20),
RACE_START_STATUS(27),
YACHT_EVENT_CODE(29),
YACHT_ACTION_CODE(31),
CHATTER_TEXT(36),
@@ -52,6 +52,7 @@ public class RaceStartStatusMessage extends Message {
putUnsignedByte((byte) notificationType.getType());
writeCRC();
rewind();
outputStream.write(getBuffer());
}
@@ -85,6 +85,8 @@ public class RaceStatusMessage extends Message{
}
writeCRC();
rewind();
outputStream.write(getBuffer());
}
@@ -62,6 +62,7 @@ public class XMLMessage extends Message{
putBytes(content.getBytes());
writeCRC();
rewind();
outputStream.write(getBuffer());
}