Upon hosting, and then creating a new instance and connecting to that IP, button transmissions work and print out on server!! :D

Took the send method out of the Message class as it didnt make sense to have it there. This meant taking it out of all subclasses too

tags: #story[1055] pair[wmu16, zyt10]
This commit is contained in:
William Muir
2017-07-18 12:22:58 +12:00
parent 63958a6717
commit e83eaa38e1
21 changed files with 248 additions and 670 deletions
@@ -1,8 +1,8 @@
package seng302.server.messages;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
/**
* Created by kre39 on 12/07/17.
@@ -15,6 +15,12 @@ public class BoatActionMessage extends Message{
public BoatActionMessage(BoatActionType actionType) {
this.actionType = actionType;
setHeader(new Header(MessageType.BOAT_ACTION, 0, (short) 1)); // the second variable is the source id
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();
}
@@ -23,30 +29,4 @@ public class BoatActionMessage extends Message{
return MESSAGE_SIZE;
}
/**
* Send this message as a stream of bytes
* @param outputStream The output stream to send the message
*/
public void send(SocketChannel outputStream) throws IOException {
System.out.println("[CLIENT] Sending boat action type: " + actionType.toString());
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
public ByteBuffer stealBuffer() {
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();
return getBuffer();
}
}