org.apache.mina.transport.socket.DatagramSessionConfig Java Examples
The following examples show how to use
org.apache.mina.transport.socket.DatagramSessionConfig.
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: TestDnsServer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public void start() throws IOException { InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0); UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort()); setTransports(transport); DatagramAcceptor acceptor = transport.getAcceptor(); acceptor.setHandler(new DnsProtocolHandler(this, store) { @Override public void sessionCreated(IoSession session) throws Exception { // USe our own codec to support AAAA testing session.getFilterChain() .addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory())); } }); ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true); // Start the listener acceptor.bind(); }
Example #2
Source File: TestDnsServer.java From servicetalk with Apache License 2.0 | 6 votes |
@Override public void start() throws IOException { InetSocketAddress address = AddressUtils.localAddress(0); UdpTransport transport = new UdpTransport(address.getHostString(), address.getPort()); setTransports(transport); DatagramAcceptor acceptor = transport.getAcceptor(); acceptor.setHandler(new DnsProtocolHandler(this, store) { @Override public void sessionCreated(IoSession session) { // Use our own codec to support AAAA testing session.getFilterChain() .addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory())); } }); ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true); // Start the listener acceptor.bind(); }
Example #3
Source File: UdpServer.java From game-server with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public void run() { synchronized (this) { if (!isRunning) { DefaultIoFilterChainBuilder chain = acceptor.getFilterChain(); if (factory == null) { factory = new DefaultProtocolCodecFactory(); } factory.getDecoder().setMaxReadSize(minaServerConfig.getMaxReadSize()); factory.getEncoder().setMaxScheduledWriteMessages(minaServerConfig.getMaxScheduledWriteMessages()); chain.addLast("codec", new ProtocolCodecFilter(factory)); threadpool = new OrderedThreadPoolExecutor(minaServerConfig.getOrderedThreadPoolExecutorSize()); chain.addLast("threadPool", new ExecutorFilter(threadpool)); if(filters != null){ filters.forEach((key, filter)->chain.addLast(key, filter)); } DatagramSessionConfig dc = acceptor.getSessionConfig(); dc.setReuseAddress(minaServerConfig.isReuseAddress()); dc.setReceiveBufferSize(minaServerConfig.getReceiveBufferSize()); dc.setSendBufferSize(minaServerConfig.getSendBufferSize()); dc.setIdleTime(IdleStatus.READER_IDLE, minaServerConfig.getReaderIdleTime()); dc.setIdleTime(IdleStatus.WRITER_IDLE, minaServerConfig.getWriterIdleTime()); dc.setBroadcast(true); dc.setCloseOnPortUnreachable(true); acceptor.setHandler(ioHandler); try { acceptor.bind(new InetSocketAddress(minaServerConfig.getPort())); LOGGER.warn("已开始监听UDP端口:{}", minaServerConfig.getPort()); } catch (IOException e) { LOGGER.warn("监听UDP端口:{}已被占用", minaServerConfig.getPort()); LOGGER.error("UDP, 服务异常", e); } } } }
Example #4
Source File: MinaUdpClient.java From game-server with MIT License | 5 votes |
/** * 设置连接配置 * * @param minaClientConfig a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. */ public void setMinaClientConfig(MinaClientConfig minaClientConfig) { if (minaClientConfig == null) { return; } this.minaClientConfig = minaClientConfig; DatagramSessionConfig dc = connector.getSessionConfig(); maxConnectCount = minaClientConfig.getMaxConnectCount(); dc.setReceiveBufferSize(minaClientConfig.getReceiveBufferSize()); // 524288 dc.setSendBufferSize(minaClientConfig.getSendBufferSize()); // 1048576 dc.setMaxReadBufferSize(minaClientConfig.getMaxReadSize()); // 1048576 factory.getDecoder().setMaxReadSize(minaClientConfig.getMaxReadSize()); }
Example #5
Source File: TftpServer.java From tftp4j with Apache License 2.0 | 5 votes |
@Override public void start() throws IOException { acceptor = new NioDatagramAcceptor(); acceptor.setDefaultLocalAddress(new InetSocketAddress(getPort())); acceptor.getFilterChain().addLast("logger-data", new LoggingFilter("tftp-server-data")); acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TftpProtocolCodecFactory())); acceptor.getFilterChain().addLast("logger-packet", new LoggingFilter("tftp-server-packet")); acceptor.setHandler(new TftpServerProtocolHandler(getDataProvider())); DatagramSessionConfig dcfg = acceptor.getSessionConfig(); dcfg.setReuseAddress(true); // dcfg.setIdleTime(IdleStatus.BOTH_IDLE, 5); acceptor.bind(); }
Example #6
Source File: HelloUdpServer.java From mina-examples with MIT License | 5 votes |
public static void main(String[] args) throws Exception { NioDatagramAcceptor acceptor = new NioDatagramAcceptor();//UDP Acceptor acceptor.getFilterChain().addLast("logging", new LoggingFilter()); acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter()); acceptor.setHandler(new HelloServerHandler()); acceptor.getSessionConfig().setReadBufferSize(2048); acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); DatagramSessionConfig dcfg = acceptor.getSessionConfig(); dcfg.setReuseAddress(true); acceptor.bind(new InetSocketAddress(PORT)); }
Example #7
Source File: NioDatagramAcceptor.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override public DatagramSessionConfig getSessionConfig() { return (DatagramSessionConfig) super.getSessionConfig(); }
Example #8
Source File: NioDatagramConnector.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override public DatagramSessionConfig getSessionConfig() { return (DatagramSessionConfig) super.getSessionConfig(); }
Example #9
Source File: NioDatagramSession.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ public DatagramSessionConfig getConfig() { return (DatagramSessionConfig) config; }
Example #10
Source File: UDPConduit.java From cxf with Apache License 2.0 | 4 votes |
public void prepare(final Message message) throws IOException { try { String address = (String)message.get(Message.ENDPOINT_ADDRESS); if (StringUtils.isEmpty(address)) { address = this.getTarget().getAddress().getValue(); } URI uri = new URI(address); if (StringUtils.isEmpty(uri.getHost())) { //NIO doesn't support broadcast, we need to drop down to raw //java.io for these String s = uri.getSchemeSpecificPart(); if (s.startsWith("//:")) { s = s.substring(3); } if (s.indexOf('/') != -1) { s = s.substring(0, s.indexOf('/')); } int port = Integer.parseInt(s); sendViaBroadcast(message, null, port); } else { final InetSocketAddress isa = new InetSocketAddress(uri.getHost(), uri.getPort()); if (isa.getAddress().isMulticastAddress()) { sendViaBroadcast(message, isa, isa.getPort()); return; } final String hp = uri.getHost() + ':' + uri.getPort(); Queue<ConnectFuture> q = connections.get(hp); ConnectFuture connFuture = null; if (q != null) { connFuture = q.poll(); } if (connFuture == null) { connFuture = connector.connect(isa); connFuture.await(); ((DatagramSessionConfig)connFuture.getSession().getConfig()).setSendBufferSize(64 * 1024); ((DatagramSessionConfig)connFuture.getSession().getConfig()).setReceiveBufferSize(64 * 1024); } connFuture.getSession().setAttribute(CXF_MESSAGE_ATTR, message); message.setContent(OutputStream.class, new UDPConduitOutputStream(connFuture)); message.getExchange().put(ConnectFuture.class, connFuture); message.getExchange().put(HOST_PORT, hp); } } catch (Exception ex) { throw new IOException(ex); } }