Mercurial > hg > RemoteEditor > Eclipse
comparison src/remoteeditor/network/REPPacketSend.java @ 34:7d80c9318695
*** empty log message ***
author | pin |
---|---|
date | Wed, 31 Jan 2007 02:06:52 +0900 |
parents | |
children | 0c5701885b09 |
comparison
equal
deleted
inserted
replaced
33:96306e8dc217 | 34:7d80c9318695 |
---|---|
1 package remoteeditor.network; | |
2 | |
3 import java.io.IOException; | |
4 import java.nio.ByteBuffer; | |
5 import java.nio.channels.SocketChannel; | |
6 | |
7 import remoteeditor.command.REPCommand; | |
8 | |
9 public class REPPacketSend { | |
10 SocketChannel socketchannel; | |
11 | |
12 public REPPacketSend(SocketChannel sc){ | |
13 socketchannel = sc; | |
14 } | |
15 | |
16 public ByteBuffer pack(REPCommand command){ | |
17 | |
18 ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string).length()*2); | |
19 buffer.clear(); // position = 0 | |
20 buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid); | |
21 buffer.putInt(command.seq); buffer.putInt(command.lineno); | |
22 buffer.putInt(command.string.length()*2); | |
23 for(int i=0;i<command.string.length();i++) { | |
24 buffer.putChar(command.string.charAt(i)); | |
25 } | |
26 buffer.flip(); // limit = current position, position = 0 | |
27 return buffer; | |
28 } | |
29 | |
30 public void send(REPCommand command){ | |
31 try { | |
32 socketchannel.write(pack(command)); | |
33 } catch (IOException e) { | |
34 e.printStackTrace(); | |
35 } | |
36 } | |
37 } |