pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
pipeline.addLast("handler", new MessageReceiveHandler()); // 비지니소 로직 처리
위와 같은 형태로 처리하면 되지 않을까 생각하고 있는데 netty 선배님들의 조언 부탁드리겠습니다.
감사합니다.
* LengthFieldBasedFrameDecoder - http://tinyurl.com/9rzasc
* 메시지상의 길이 필드를 보고 프레임을 디코드
* LengthFieldPrepender - http://tinyurl.com/852d57
* 메시지에 메시지의 길이를 나타내는 바이너리 헤더를 추가
netty release 문서에 요런내용이 있는걸 보니 일단 방향은 제대로 잡은 것 같네요.
LengthFieldBasedFrameDecoder 의 생성자 파라메터 중 마지막 2개 값이 선뜻 잘 이해가 안가는데요. 혹시 설명해주실 수 있는 분 계실까요?
@param lengthAdjustment - 길이 필드의 값에 더하는 보정 값
@param initialBytesToStrip - 디코드 된 프레임으로부터 스트립하는 최초의 바이트 수
파트너사의 TCP 서버에 요청 / 응답을 받는 클라이언트를 netty 로 개발해보고자 합니다. netty 를 처음 접하다 보니 고민이 많네요.
public SamdasuDecoder extends ReplayingDecoder {
Enum MSG {LENGTH, F1, F2, F3, BODY };
@Override
public void decode (...) throws Excpetion {
switch (state()) {
case LENGTH:
length = in.readInt();
checkpoint(F1);
case F1:
.... read
checkpoint(F2);
case F2:
.... read
checkpoint(F3);
case F3:
.... read
checkpoint(BODY);
case BODY:
byte[] buf = new byte[length];
in.readBytes(buf);
out.add(buf);
}
}
}파트너사의 TCP 서버에 요청 / 응답을 받는 클라이언트를 netty 로 개발해보고자 합니다. netty 를 처음 접하다 보니 고민이 많네요.
public SamdasuDecdoer extends ReplayingDecdoer {
private int length;
}ReplayingDecoder 로 전문을 받은 후 다른 처리를 위해서 다음 handler 로 넘기려면 어떻게 처리해야 하나요?
별도의 이벤트를 트리거주어야 다른 handler 에서 처리 가능한 걸까요 ?
pipeLine 에는 2개의 handler 를 추가해뒀는데 앞순서의 replayingDecoder 만 수행되네요
ReplayingDecoder의 경우 ByteToMessageDecoder를 상속받아 Byte 메세지를 모두 다 받을 수 있도록 구현돼 있습니다.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object>out) throws Exception {
int message = in.readInt();
int bodys = in.readInt();
// recv
// passing
out.add(....);
}