Java Code Examples for org.apache.mina.transport.socket.nio.NioDatagramConnector#setHandler()
The following examples show how to use
org.apache.mina.transport.socket.nio.NioDatagramConnector#setHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinaUdpClient.java From game-server with MIT License | 5 votes |
/** * 初始化tcp连接 * * @param clientProtocolHandler */ private void init(IoHandler clientProtocolHandler) { connector = new NioDatagramConnector(); connector.getFilterChain().addLast("codec", codecFilter); connector.setHandler(clientProtocolHandler); connector.setConnectTimeoutMillis(60000L); connector.setConnectTimeoutCheckInterval(10000); }
Example 2
Source File: TftpServerProtocolHandler.java From tftp4j with Apache License 2.0 | 4 votes |
@Override public void messageReceived(IoSession session, Object message) throws Exception { TftpPacket packet = (TftpPacket) message; SocketAddress address = session.getRemoteAddress(); LOG.info("Address is " + address); switch (packet.getOpcode()) { case RRQ: { TftpRequestPacket request = (TftpRequestPacket) packet; TftpData source = provider.open(request.getFilename()); if (source == null) { session.write(new TftpErrorPacket(address, TftpErrorCode.FILE_NOT_FOUND), address); session.close(false); } else { final NioDatagramConnector connector = new NioDatagramConnector(); TftpTransfer transfer = new TftpReadTransfer(address, source, request.getBlockSize()); TftpTransferProtocolHandler handler = new TftpTransferProtocolHandler(connector, transfer); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TftpProtocolCodecFactory())); connector.getFilterChain().addLast("logger-packet", new LoggingFilter("tftp-transfer-packet")); connector.setHandler(handler); ConnectFuture future = connector.connect(address); future.addListener(handler); } break; } case WRQ: { session.write(new TftpErrorPacket(address, TftpErrorCode.PERMISSION_DENIED), address); session.close(false); break; } case ACK: { break; } case DATA: { LOG.warn("Unexpected TFTP " + packet.getOpcode() + " packet: " + packet); session.write(new TftpErrorPacket(address, TftpErrorCode.ILLEGAL_OPERATION), address); session.close(false); break; } case ERROR: { TftpErrorPacket error = (TftpErrorPacket) packet; LOG.error("Received TFTP error packet: " + error); session.close(true); break; } } }