use of org.webpieces.nio.api.channels.TCPServerChannel in project webpieces by deanhiller.
the class AsyncServerManagerImpl method createTcpServerImpl.
private AsyncServer createTcpServerImpl(AsyncConfig config, AsyncDataListener listener, SSLEngineFactory sslFactory) {
String id = config.id;
ConnectedChannels connectedChannels = new ConnectedChannels();
ProxyDataListener proxyListener = new ProxyDataListener(connectedChannels, listener);
DefaultConnectionListener connectionListener = new DefaultConnectionListener(connectedChannels, proxyListener);
TCPServerChannel serverChannel;
if (sslFactory != null)
serverChannel = channelManager.createTCPServerChannel(id, connectionListener, sslFactory);
else
serverChannel = channelManager.createTCPServerChannel(id, connectionListener);
//MUST be called before bind...
serverChannel.setReuseAddress(true);
serverChannel.configure(config.functionToConfigureBeforeBind);
return new AsyncServerImpl(serverChannel, connectionListener, proxyListener);
}
use of org.webpieces.nio.api.channels.TCPServerChannel in project webpieces by deanhiller.
the class AsyncServerManagerImpl method createTcpServerImpl.
private AsyncServer createTcpServerImpl(AsyncConfig config, AsyncDataListener listener, SSLEngineFactory sslFactory, boolean isUpgradable) {
if (config.id == null)
throw new IllegalArgumentException("config.id must not be null");
String id = channelManager.getName() + "." + config.id;
ConnectedChannels connectedChannels = new ConnectedChannels(id, metrics);
ProxyDataListener proxyListener = new ProxyDataListener(connectedChannels, listener);
DefaultConnectionListener connectionListener = new DefaultConnectionListener(id, connectedChannels, proxyListener);
TCPServerChannel serverChannel;
if (sslFactory != null) {
if (isUpgradable) {
// create plain text that can accept SSL immediately OR change to SSL later
serverChannel = channelManager.createTCPUpgradableChannel(config.id, connectionListener, sslFactory);
} else {
serverChannel = channelManager.createTCPServerChannel(config.id, connectionListener, sslFactory);
}
} else {
serverChannel = channelManager.createTCPServerChannel(config.id, connectionListener);
}
// MUST be called before bind...
serverChannel.setReuseAddress(true);
serverChannel.configure(config.functionToConfigureBeforeBind);
return new AsyncServerImpl(serverChannel, connectionListener, proxyListener, sslFactory);
}
use of org.webpieces.nio.api.channels.TCPServerChannel in project webpieces by deanhiller.
the class TestBasicSsl method testBasic.
@Test
public void testBasic() throws InterruptedException, ExecutionException {
ChannelManager svrMgr = createSvrChanMgr("server");
SelfSignedSSLEngineFactory sslFactory = new SelfSignedSSLEngineFactory();
TCPServerChannel svrChannel = svrMgr.createTCPServerChannel("svrChan", mockConnListener, sslFactory);
svrChannel.bind(new InetSocketAddress(8444));
int port = svrChannel.getLocalAddress().getPort();
//don't really need to use a separate chan mgr but we will here..
ChannelManager chanMgr = createSvrChanMgr("client");
TCPChannel channel = chanMgr.createTCPChannel("client", sslFactory.createEngineForClient("cvs.xsoftware.biz", port));
CompletableFuture<Channel> future = channel.connect(new InetSocketAddress("localhost", port), mockClientDataListener);
future.get();
byte[] data = new byte[] { 0, 2, 4, 6, 8, 10 };
ByteBuffer buf = ByteBuffer.wrap(data);
channel.write(buf);
ByteBuffer result = mockSvrDataListener.getFirstBuffer().get();
byte[] newData = new byte[result.remaining()];
result.get(newData);
Assert.assertEquals(data.length, newData.length);
for (int i = 0; i < data.length; i++) {
Assert.assertEquals(data[i], newData[i]);
}
//verify sniServerName was used in looking up security cert.
String host = sslFactory.getCachedHost();
Assert.assertEquals("cvs.xsoftware.biz", host);
}
use of org.webpieces.nio.api.channels.TCPServerChannel in project webpieces by deanhiller.
the class TestExampleSessions method startServer.
private InetSocketAddress startServer() throws Exception {
TCPServerChannel server = svc.createTCPServerChannel("server", null);
// bind to 0 allows it to bind to any port...
server.bind(new InetSocketAddress(0));
server.registerServerSocketChannel(new MyServerSocketListener());
return server.getLocalAddress();
}
use of org.webpieces.nio.api.channels.TCPServerChannel in project webpieces by deanhiller.
the class TestExample method startServer.
private InetSocketAddress startServer() throws Exception {
TCPServerChannel server = svc.createTCPServerChannel("server", null);
// bind to 0 allows it to bind to any port...
server.bind(new InetSocketAddress(0));
server.registerServerSocketChannel(new MyServerSocketListener());
return server.getLocalAddress();
}
Aggregations