Mercurial > hg > RemoteEditor > Eclipse
diff src/remoteeditor/network/REPPacketSend.java @ 34:7d80c9318695
*** empty log message ***
author | pin |
---|---|
date | Wed, 31 Jan 2007 02:06:52 +0900 |
parents | |
children | 0c5701885b09 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/remoteeditor/network/REPPacketSend.java Wed Jan 31 02:06:52 2007 +0900 @@ -0,0 +1,37 @@ +package remoteeditor.network; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +import remoteeditor.command.REPCommand; + +public class REPPacketSend { + SocketChannel socketchannel; + + public REPPacketSend(SocketChannel sc){ + socketchannel = sc; + } + + public ByteBuffer pack(REPCommand command){ + + ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string).length()*2); + buffer.clear(); // position = 0 + buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid); + buffer.putInt(command.seq); buffer.putInt(command.lineno); + buffer.putInt(command.string.length()*2); + for(int i=0;i<command.string.length();i++) { + buffer.putChar(command.string.charAt(i)); + } + buffer.flip(); // limit = current position, position = 0 + return buffer; + } + + public void send(REPCommand command){ + try { + socketchannel.write(pack(command)); + } catch (IOException e) { + e.printStackTrace(); + } + } +}