Mercurial > hg > RemoteEditor > REPSessionManager
view rep/REPPacketSend.java @ 4:c0db426126b6
*** empty log message ***
author | pin |
---|---|
date | Tue, 11 Sep 2007 18:05:29 +0900 |
parents | e41994ce73c7 |
children | 689622193437 |
line wrap: on
line source
package rep; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class REPPacketSend { SocketChannel socketchannel; public REPPacketSend(SocketChannel sc){ socketchannel = sc; } public ByteBuffer pack(REPCommand command){ System.out.println("send command: " + command.toString()); 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)); //System.out.println(command.toString()); } catch (IOException e) { e.printStackTrace(); } } }