Search in sources :

Example 26 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class SslChannelService method createTCPChannel.

@Override
public TCPChannel createTCPChannel(String id, SSLEngine engine) {
    if (engine == null || id == null)
        throw new IllegalArgumentException("no arguments can be null");
    Function<SslListener, AsyncSSLEngine> function = l -> AsyncSSLFactory.create(id, engine, pool, l);
    TCPChannel channel = mgr.createTCPChannel(id);
    SslTCPChannel sslChannel = new SslTCPChannel(function, channel);
    return sslChannel;
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) DatagramChannel(org.webpieces.nio.api.channels.DatagramChannel) AsyncSSLFactory(org.webpieces.ssl.api.AsyncSSLFactory) TCPServerChannel(org.webpieces.nio.api.channels.TCPServerChannel) ConnectionListener(org.webpieces.nio.api.handlers.ConnectionListener) Function(java.util.function.Function) ChannelManager(org.webpieces.nio.api.ChannelManager) SSLEngine(javax.net.ssl.SSLEngine) UDPChannel(org.webpieces.nio.api.channels.UDPChannel) AsyncSSLEngine(org.webpieces.ssl.api.AsyncSSLEngine) DatagramListener(org.webpieces.nio.api.handlers.DatagramListener) SSLEngineFactory(org.webpieces.nio.api.SSLEngineFactory) SslListener(org.webpieces.ssl.api.SslListener) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncSSLEngine(org.webpieces.ssl.api.AsyncSSLEngine) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SslListener(org.webpieces.ssl.api.SslListener)

Example 27 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class EventClient method start.

public void start() throws IOException, InterruptedException {
    ChannelService mgr = ChannelServiceFactory.createDefaultChannelMgr("EventServer");
    mgr.start();
    SSLEngineFactory sslFactory = new MockSSLEngineFactory();
    Settings h = new Settings(sslFactory, null);
    TCPChannel channel = mgr.createTCPChannel("SvrChan", h);
    InetAddress addr = InetAddress.getByName("192.168.1.102");
    InetSocketAddress sockAddr = new InetSocketAddress(addr, 801);
    log.info("Connecting to server=" + sockAddr);
    channel.oldConnect(sockAddr, this);
}
Also used : ChannelService(org.webpieces.nio.api.deprecated.ChannelService) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) MockSSLEngineFactory(org.webpieces.nio.api.testutil.MockSSLEngineFactory) SSLEngineFactory(org.webpieces.nio.api.libs.SSLEngineFactory) InetAddress(java.net.InetAddress) Settings(org.webpieces.nio.api.deprecated.Settings) MockSSLEngineFactory(org.webpieces.nio.api.testutil.MockSSLEngineFactory)

Example 28 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class TryRealConnection method xxxtestRealConnection.

public void xxxtestRealConnection() throws Exception {
    MockObject mockConnect = MockObjectFactory.createMock(ConnectionCallback.class);
    Settings h = new Settings(new MockSSLEngineFactory(), null);
    TCPChannel channel = chanMgr.createTCPChannel("testId", h);
    channel.bind(loopBackAddr);
    log.trace("aaaaa");
    MockObject handler = new MockDataHandler();
    channel.registerForReads((DataListener) handler);
    //		InetAddress host = InetAddress.getByName("shell.sourceforge.net");
    InetAddress host = InetAddress.getByName("www.xsoftware.biz");
    InetSocketAddress addr = new InetSocketAddress(host, 22);
    channel.oldConnect(addr, (ConnectionCallback) mockConnect);
    mockConnect.expect("connected");
    handler.addIgnore("getBuffer");
    //CalledMethod method = 
    handler.expect("incomingData");
//		ByteBuffer b = (ByteBuffer)method.getAllParams()[1];
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) MockDataHandler(org.webpieces.nio.api.testutil.MockDataHandler) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) MockObject(biz.xsoftware.mock.MockObject) Settings(org.webpieces.nio.api.deprecated.Settings) MockSSLEngineFactory(org.webpieces.nio.api.testutil.MockSSLEngineFactory)

Example 29 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class TestExample method runClient.

private void runClient(SocketAddress svrAddr) throws Exception {
    TCPChannel client = svc.createTCPChannel("client", null);
    client.bind(new InetSocketAddress(0));
    //we will just go with synchronous connect today...(could have used the asynch one though)
    client.oldConnect(svrAddr);
    client.registerForReads(new MyDataListener("client"));
    //because this is not a real example and the server and client are both here, we
    //will sleep and wait for the svrTCPChannel to be cached!!  Normally, this is
    //not needed
    Thread.sleep(2000);
    String msg = "hello world";
    ByteBuffer b = ByteBuffer.allocate(100);
    HELPER.putString(b, msg);
    b.flip();
    client.oldWrite(b);
    b.rewind();
    svrTCPChannel.oldWrite(b);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer)

Example 30 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class TestExampleSessions method runClient.

private void runClient(SocketAddress svrAddr) throws Exception {
    TCPChannel client = svc.createTCPChannel("client", null);
    client.bind(new InetSocketAddress(0));
    //we will just go with synchronous connect today...(could have used the asynch one though)
    client.oldConnect(svrAddr);
    client.registerForReads(new MyDataListener("client"));
    //because this is not a real example and the server and client are both here, we
    //will sleep and wait for the svrTCPChannel to be cached!!  Normally, this is
    //not needed
    Thread.sleep(2000);
    String msg = "hello world";
    ByteBuffer b = ByteBuffer.allocate(100);
    HELPER.putString(b, msg);
    b.flip();
    client.oldWrite(b);
    b.rewind();
    client.oldWrite(b);
    b.rewind();
    svrTCPChannel.oldWrite(b);
    b.rewind();
    client.oldWrite(b);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TCPChannel (org.webpieces.nio.api.channels.TCPChannel)39 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)10 CalledMethod (biz.xsoftware.mock.CalledMethod)8 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)6 ChannelManager (org.webpieces.nio.api.ChannelManager)5 Channel (org.webpieces.nio.api.channels.Channel)5 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)4 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)4 FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 BufferPool (org.webpieces.data.api.BufferPool)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Executor (java.util.concurrent.Executor)2 Test (org.junit.Test)2 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)2