NioEventLoopGroup worker = new NioEventLoopGroup();
bootstrap.group(worker); bootstrap.channel(NioSocketChannel.class);
bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected
void initChannel(Channel channel) throws Exception { //BIG_ENDIAN
channel.pipeline().addLast(new
LengthFieldBasedFrameDecoder(ByteOrder.BIG_ENDIAN,1024*1024,2,2,-4,0,true));
channel.pipeline().addLast(new ClientHandler()); } }); ChannelFuture f =
bootstrap.connect("127.0.0.1", 3000); //send msg byte[] msg = "I am java
netty client msg".getBytes(); //If msg is a simple string, go can accept
it. If it is changed to a byte array, go will block to conn.Read (buffer).
f.channel().writeAndFlush(msg)
func main() { listen, err := net.Listen("tcp", "127.0.0.1:30000") if err !=
nil { fmt.Println("listen failed, err:", err) return } defer listen.Close()
for { conn, err := listen.Accept() if err != nil { fmt.Println("accept
failed, err:", err) continue } go func() { defer conn.Close() var num int32
buffer := make([]byte, 6) _, err := conn.Read(buffer) // If the byte []
byte copy sent by java netty is doubled in this line
if err != nil { return } buf := bytes.NewReader(buffer) err =
binary.Read(buf, binary.BigEndian, &num) fmt.Println(buf) }() } }
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/9c7b7e3f-0e05-4aa4-9de9-6fad33fe56cf%40googlegroups.com.