2014-03-12 82 views
3

如下圖所示,我可以讀取IoSession發送的字節[],而不需要協議解碼器。如何將byte []寫入IoSession

IoBuffer in = (IoBuffer) message; 
byte[] inBytes = in.array(); 
int length = inBytes[0]; 
inBytes = Arrays.copyOfRange(inBytes, 1, length + 1); 
ByteString incomingMessage = ByteString.copyFrom(inBytes); 

但是當我嘗試這樣做:

someIoSession.write(incomingMessage.toByteArray()); 

我碰到下面的錯誤。

Don't know how to handle message of type XXXX. Are you missing a protocol encoder?

我怎麼能只寫字節到IoSession?

回答

0
someIoSession.write(IoBuffer.wrap(incomingMessage.toByteArray())); 
+1

雖然這段代碼可能會解決這個問題,但應該總是給它添加一個解釋。 – BDL

相關問題