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?
雖然這段代碼可能會解決這個問題,但應該總是給它添加一個解釋。 – BDL