Getting boat locations from race simulator & bug fixes

- Boat locations that are generated by the simulator are sent to the client as they happen
- Fixed heading and lat/lon encoding
- Fixed a bug where the header wasn't included in the sent byte stream
- Fixed the format of data as it's sent to the client.
- Data is now sent using a channel
- Removed tests that don't work with channels

Tags: #story[829]
This commit is contained in:
Michael Rausch
2017-04-29 19:38:21 +12:00
parent 8a04a0e5b7
commit 3e97f016d5
16 changed files with 330 additions and 354 deletions
@@ -4,35 +4,44 @@ import seng302.server.messages.Message;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.Channels;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.List;
class StreamingServerSocket {
private java.net.ServerSocket socket;
private Socket client;
private ServerSocketChannel socket;
private SocketChannel client;
private List<Socket> clients;
private short seqNum;
private boolean isServerStarted;
StreamingServerSocket(int port) throws IOException{
socket = new java.net.ServerSocket(port);
socket = ServerSocketChannel.open();
socket.socket().bind(new InetSocketAddress("localhost", port));
clients = new ArrayList<>();
socket.setSoTimeout(10000);
//socket.setSoTimeout(10000);
seqNum = 0;
isServerStarted = false;
}
void start(){
System.out.println("Listening For Connections");
ServerThread.serverLog("Listening For Connections",0);
try {
client = socket.accept();
} catch (IOException e) {
e.getMessage();
}
if (client == null){
if (client.socket() == null){
start();
}
else{
System.out.println("client connected from " + client.getInetAddress());
isServerStarted = true;
ServerThread.serverLog("client connected from " + client.socket().getInetAddress(),0);
}
}
@@ -41,8 +50,9 @@ class StreamingServerSocket {
return;
}
DataOutputStream outputStream = new DataOutputStream(client.getOutputStream());
message.send(outputStream);
//DataOutputStream outputStream = new DataOutputStream(client.getOutputStream());
//System.out.println(client);
message.send(client);
seqNum++;
}
@@ -50,4 +60,8 @@ class StreamingServerSocket {
public short getSequenceNumber(){
return seqNum;
}
public boolean isStarted(){
return isServerStarted;
}
}