Moved Message Type constants to own class
This commit is contained in:
parent
0444724233
commit
709cad9919
@ -124,7 +124,7 @@ class BufferedNetworkStack {
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_PRINT:
|
||||
case MessageType.CMD_PRINT:
|
||||
System.out.println(toString());
|
||||
break;
|
||||
|
||||
|
||||
@ -6,11 +6,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public class BufferedNetworkStackClient {
|
||||
protected static final byte CMD_PUSH = '0';
|
||||
protected static final byte CMD_DATA = '1';
|
||||
protected static final byte CMD_POP = '2';
|
||||
protected static final byte CMD_PRINT = '3';
|
||||
|
||||
protected static final int BUF_SIZE = 128;
|
||||
|
||||
private DatagramChannel channel = null;
|
||||
@ -28,7 +23,7 @@ public class BufferedNetworkStackClient {
|
||||
InetSocketAddress dest = new InetSocketAddress(host, port);
|
||||
|
||||
buf.clear();
|
||||
buf.put(CMD_PUSH);
|
||||
buf.put(MessageType.CMD_PUSH);
|
||||
|
||||
byte[] length = String.valueOf(s.length()).getBytes();
|
||||
buf.put(length);
|
||||
@ -89,7 +84,7 @@ public class BufferedNetworkStackClient {
|
||||
}
|
||||
|
||||
InetSocketAddress dest = new InetSocketAddress(host, port);
|
||||
channel.send(ByteBuffer.wrap(new byte[] { CMD_POP }), dest);
|
||||
channel.send(ByteBuffer.wrap(new byte[] { MessageType.CMD_POP }), dest);
|
||||
|
||||
channel.receive(buf);
|
||||
byte[] receivedData = buf.array();
|
||||
@ -105,6 +100,7 @@ public class BufferedNetworkStackClient {
|
||||
}
|
||||
|
||||
InetSocketAddress dest = new InetSocketAddress(host, port);
|
||||
channel.send(ByteBuffer.wrap(new byte[] { CMD_PRINT }), dest);
|
||||
channel.send(ByteBuffer.wrap(new byte[] { MessageType.CMD_PRINT }),
|
||||
dest);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user