Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import io.netty.channel.ChannelInitializer;
  2. import io.netty.channel.ChannelPipeline;
  3. import io.netty.channel.socket.SocketChannel;
  4. public class ServerAdapterInitializer extends ChannelInitializer<SocketChannel> {
  5.  
  6. @Override
  7. protected void initChannel(SocketChannel channel) throws Exception {
  8. ChannelPipeline pipeline = channel.pipeline();
  9.  
  10. pipeline.addLast("encoder", new Encoder());//Кодирует
  11. pipeline.addLast("decoder", new Decoder());//Расшифровывает
  12.  
  13. pipeline.addLast("handler", new ServerAdapterHandler());// ServerAdapterHandler() будет принимать все пакеты от клиентов.
  14. }
  15. }
  16.  
  17. import com.sun.xml.internal.ws.api.message.Packet;
  18. import io.netty.buffer.ByteBuf;
  19. import io.netty.channel.ChannelHandlerContext;
  20. import io.netty.handler.codec.MessageToByteEncoder;
  21.  
  22. public class Encoder extends MessageToByteEncoder<Packet> {
  23.  
  24. @Override
  25. protected void encode(ChannelHandlerContext channelHandlerContext, Packet packet, ByteBuf byteBuf) throws Exception {
  26.  
  27. }
  28. }
Add Comment
Please, Sign In to add comment