WIP: Implemented a temporary workaround to send an instance test to client server upon connection.

Still needs reengineering to change socket channels for sending to ouput stream in the message class.
Only client to server "working".

#story[1047] #pair[hyi25, wmu16] #pair[cir27, zyt10]
This commit is contained in:
Haoming Yin
2017-07-17 17:00:04 +12:00
parent 4b8ac32ca9
commit 63958a6717
12 changed files with 154 additions and 68 deletions
@@ -0,0 +1,53 @@
package seng302.client;
import java.io.IOException;
import seng302.server.StreamingServerSocket;
import seng302.server.messages.BoatActionMessage;
/**
* Created by kre39 on 13/07/17.
*/
public class ClientTransmitterThread implements Runnable {
private StreamingServerSocket server;
private final int PORT_NUMBER = 0;
private static final int LOG_LEVEL = 1;
public ClientTransmitterThread(String threadName){
Thread runner = new Thread(this, threadName);
runner.setDaemon(true);
runner.start();
}
static void serverLog(String message, int logLevel){
if(logLevel <= LOG_LEVEL){
System.out.println("[SERVER] " + message);
}
}
public void run() {
try{
// Needs to connect to the server: Currently no server is being connect so the boat action keys are not being sent
server = new StreamingServerSocket(PORT_NUMBER);
}
catch (IOException e){
serverLog("Failed to bind socket: " + e.getMessage(), 0);
}
// Wait for client to connect
server.start();
}
/**
* Send the post-start race course information
*/
public void sendBoatActionMessage(BoatActionMessage boatActionMessage) {
try {
server.send(boatActionMessage);
} catch (IOException e) {
e.printStackTrace();
}
}
}