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
@@ -1,6 +1,7 @@
package seng302.server.messages;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
/**
@@ -27,7 +28,7 @@ public class BoatActionMessage extends Message{
* @param outputStream The output stream to send the message
*/
public void send(SocketChannel outputStream) throws IOException {
System.out.println("Sending boat action type: " + actionType.toString());
System.out.println("[CLIENT] Sending boat action type: " + actionType.toString());
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
@@ -37,4 +38,15 @@ public class BoatActionMessage extends Message{
outputStream.write(getBuffer());
}
public ByteBuffer stealBuffer() {
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();
return getBuffer();
}
}