Search in sources :

Example 6 with Address

use of zmq.io.net.Address in project jeromq by zeromq.

the class SessionBase method startConnecting.

private void startConnecting(boolean wait) {
    assert (active);
    // Choose I/O thread to run connecter in. Given that we are already
    // running in an I/O thread, there must be at least one available.
    IOThread ioThread = chooseIoThread(options.affinity);
    assert (ioThread != null);
    // Create the connecter object.
    NetProtocol protocol = addr.protocol();
    if (protocol == null) {
        errno.set(ZError.EPROTONOSUPPORT);
        return;
    }
    switch(protocol) {
        case tcp:
            if (options.socksProxyAddress != null) {
                Address proxyAddress = new Address(NetProtocol.tcp, options.socksProxyAddress);
                SocksConnecter connecter = new SocksConnecter(ioThread, this, options, addr, proxyAddress, wait);
                launchChild(connecter);
            } else {
                TcpConnecter connecter = new TcpConnecter(ioThread, this, options, addr, wait);
                launchChild(connecter);
            }
            break;
        case ipc:
            {
                IpcConnecter connecter = new IpcConnecter(ioThread, this, options, addr, wait);
                launchChild(connecter);
            }
            break;
        case tipc:
            {
                TipcConnecter connecter = new TipcConnecter(ioThread, this, options, addr, wait);
                launchChild(connecter);
            }
            break;
        case pgm:
        case epgm:
            {
                assert (options.type == ZMQ.ZMQ_PUB || options.type == ZMQ.ZMQ_XPUB || options.type == ZMQ.ZMQ_SUB || options.type == ZMQ.ZMQ_XSUB);
                // For EPGM transport with UDP encapsulation of PGM is used.
                boolean udpEncapsulation = protocol == NetProtocol.epgm;
                // exists with PGM anyway.
                if (options.type == ZMQ.ZMQ_PUB || options.type == ZMQ.ZMQ_XPUB) {
                    // PGM sender.
                    PgmSender pgmSender = new PgmSender(ioThread, options);
                    boolean rc = pgmSender.init(udpEncapsulation, addr);
                    assert (rc);
                    sendAttach(this, pgmSender);
                } else {
                    // PGM receiver.
                    PgmReceiver pgmReceiver = new PgmReceiver(ioThread, options);
                    boolean rc = pgmReceiver.init(udpEncapsulation, addr);
                    assert (rc);
                    sendAttach(this, pgmReceiver);
                }
            }
            break;
        case norm:
            {
                // exists with NORM anyway.
                if (options.type == ZMQ.ZMQ_PUB || options.type == ZMQ.ZMQ_XPUB) {
                    // NORM sender.
                    NormEngine normSender = new NormEngine(ioThread, options);
                    boolean rc = normSender.init(addr, true, false);
                    assert (rc);
                    sendAttach(this, normSender);
                } else {
                    // NORM receiver.
                    NormEngine normReceiver = new NormEngine(ioThread, options);
                    boolean rc = normReceiver.init(addr, false, true);
                    assert (rc);
                    sendAttach(this, normReceiver);
                }
            }
            break;
        default:
            assert (false);
            break;
    }
}
Also used : IpcConnecter(zmq.io.net.ipc.IpcConnecter) SocksConnecter(zmq.io.net.tcp.SocksConnecter) Address(zmq.io.net.Address) TipcConnecter(zmq.io.net.tipc.TipcConnecter) PgmReceiver(zmq.io.net.pgm.PgmReceiver) NormEngine(zmq.io.net.norm.NormEngine) NetProtocol(zmq.io.net.NetProtocol) PgmSender(zmq.io.net.pgm.PgmSender) TcpConnecter(zmq.io.net.tcp.TcpConnecter)

Example 7 with Address

use of zmq.io.net.Address in project jeromq by zeromq.

the class TcpAddressTest method testBad.

@Test
public void testBad() {
    try {
        Address addr = new Address(NetProtocol.tcp, "ggglocalhostxxx.google.com:80");
        addr.resolve(true);
        addr.resolved();
        Assert.fail();
    } catch (ZMQException e) {
        Assert.assertEquals(ZError.EADDRNOTAVAIL, e.getErrorCode());
        Assert.assertEquals(e.getCause().getMessage(), e.getMessage());
    }
}
Also used : Address(zmq.io.net.Address) Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) ZMQException(org.zeromq.ZMQException) Test(org.junit.Test)

Example 8 with Address

use of zmq.io.net.Address in project jeromq by zeromq.

the class TcpAddressTest method parsesIpv6AddressNotWanted.

@Test
public void parsesIpv6AddressNotWanted() throws IOException {
    try {
        String addressString = "2000::a1";
        int port = Utils.findOpenPort();
        Address addr = new Address(NetProtocol.tcp, addressString + ":" + port);
        addr.resolve(false);
        InetSocketAddress expected = new InetSocketAddress(addressString, port);
        Address.IZAddress resolved = addr.resolved();
        assertEquals(expected, resolved.address());
        InetSocketAddress sa = (InetSocketAddress) resolved.address();
        Assert.assertTrue(sa.getAddress() instanceof Inet6Address);
        Assert.assertEquals(port, sa.getPort());
        Assert.fail();
    } catch (ZMQException e) {
        Assert.assertEquals(ZError.EADDRNOTAVAIL, e.getErrorCode());
        Assert.assertEquals("2000::a1 not found matching IPv4/IPv6 settings", e.getMessage());
    }
}
Also used : Address(zmq.io.net.Address) Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) ZMQException(org.zeromq.ZMQException) Test(org.junit.Test)

Example 9 with Address

use of zmq.io.net.Address in project jeromq by zeromq.

the class TcpAddressTest method parsesIpv6AddressBracket.

@Test
public void parsesIpv6AddressBracket() throws IOException {
    String addressString = "2000::a1";
    int port = Utils.findOpenPort();
    Address addr = new Address(NetProtocol.tcp, "[" + addressString + "]:" + port);
    addr.resolve(true);
    InetSocketAddress expected = new InetSocketAddress(addressString, port);
    Address.IZAddress resolved = addr.resolved();
    assertEquals(expected, resolved.address());
    InetSocketAddress sa = (InetSocketAddress) resolved.address();
    Assert.assertTrue(sa.getAddress() instanceof Inet6Address);
    Assert.assertEquals(port, sa.getPort());
}
Also used : Address(zmq.io.net.Address) Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) Test(org.junit.Test)

Example 10 with Address

use of zmq.io.net.Address in project jeromq by zeromq.

the class TcpAddressTest method testUnspecifiedIPv6Star.

@Test
public void testUnspecifiedIPv6Star() throws IOException {
    int port = Utils.findOpenPort();
    Address addr = new Address(NetProtocol.tcp, "*:" + port);
    addr.resolve(true);
    Address.IZAddress resolved = addr.resolved();
    InetSocketAddress sa = (InetSocketAddress) resolved.address();
    Assert.assertTrue(sa.getAddress() instanceof Inet6Address);
    String hostString = sa.getHostString();
    Assert.assertTrue("::".equals(hostString) || "0:0:0:0:0:0:0:0".equals(hostString));
    Assert.assertEquals(port, sa.getPort());
}
Also used : Address(zmq.io.net.Address) Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) Test(org.junit.Test)

Aggregations

Address (zmq.io.net.Address)12 InetSocketAddress (java.net.InetSocketAddress)10 Inet4Address (java.net.Inet4Address)9 Inet6Address (java.net.Inet6Address)9 Test (org.junit.Test)9 ZMQException (org.zeromq.ZMQException)2 NetProtocol (zmq.io.net.NetProtocol)2 IOException (java.io.IOException)1 SocketAddress (java.net.SocketAddress)1 Ignore (org.junit.Ignore)1 IOThread (zmq.io.IOThread)1 SessionBase (zmq.io.SessionBase)1 IZAddress (zmq.io.net.Address.IZAddress)1 IpcConnecter (zmq.io.net.ipc.IpcConnecter)1 NormEngine (zmq.io.net.norm.NormEngine)1 PgmReceiver (zmq.io.net.pgm.PgmReceiver)1 PgmSender (zmq.io.net.pgm.PgmSender)1 SocksConnecter (zmq.io.net.tcp.SocksConnecter)1 TcpConnecter (zmq.io.net.tcp.TcpConnecter)1 TipcConnecter (zmq.io.net.tipc.TipcConnecter)1