Search in sources :

Example 16 with SocketAddress

use of java.net.SocketAddress in project pinpoint by naver.

the class NetworkAvailabilityCheckPacketFilterTest method testFilter.

@Test
public void testFilter() throws Exception {
    SocketAddress localSocketAddress = senderSocket.getLocalSocketAddress();
    logger.debug("localSocket:{}", localSocketAddress);
    NetworkAvailabilityCheckPacket packet = new NetworkAvailabilityCheckPacket();
    boolean skipResult = filter.filter(receiverSocket, packet, new InetSocketAddress("localhost", senderSocket.getLocalPort()));
    Assert.assertEquals(skipResult, TBaseFilter.BREAK);
    DatagramPacket receivePacket = new DatagramPacket(new byte[100], 100);
    senderSocket.receive(receivePacket);
    Assert.assertEquals(receivePacket.getLength(), NetworkAvailabilityCheckPacket.DATA_OK.length);
    Assert.assertArrayEquals(Arrays.copyOf(receivePacket.getData(), NetworkAvailabilityCheckPacket.DATA_OK.length), NetworkAvailabilityCheckPacket.DATA_OK);
}
Also used : NetworkAvailabilityCheckPacket(com.navercorp.pinpoint.thrift.io.NetworkAvailabilityCheckPacket) InetSocketAddress(java.net.InetSocketAddress) DatagramPacket(java.net.DatagramPacket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 17 with SocketAddress

use of java.net.SocketAddress in project openhab1-addons by openhab.

the class S7Client method TCPConnect.

private int TCPConnect() {
    SocketAddress sockaddr = new InetSocketAddress(IPAddress, ISOTCP);
    LastError = 0;
    try {
        TCPSocket = new Socket();
        TCPSocket.connect(sockaddr, 5000);
        TCPSocket.setTcpNoDelay(true);
        InStream = new DataInputStream(TCPSocket.getInputStream());
        OutStream = new DataOutputStream(TCPSocket.getOutputStream());
    } catch (IOException e) {
        LastError = errTCPConnectionFailed;
    }
    return LastError;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DataInputStream(java.io.DataInputStream) Socket(java.net.Socket)

Example 18 with SocketAddress

use of java.net.SocketAddress in project openhab1-addons by openhab.

the class TCPConnector method open.

/**
     * {@inheritDoc}
     **/
public void open() {
    try {
        tcpSocket = new Socket();
        SocketAddress TPIsocketAddress = new InetSocketAddress(ipAddress, tcpPort);
        tcpSocket.connect(TPIsocketAddress, connectTimeout);
        tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
        tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));
        connected = true;
        // Start the TCP Listener
        TCPListener = new TCPListener();
        TCPListener.start();
    } catch (UnknownHostException exception) {
        logger.error("open(): Unknown Host Exception: ", exception);
        connected = false;
    } catch (SocketException socketException) {
        logger.error("open(): Socket Exception: ", socketException);
        connected = false;
    } catch (IOException ioException) {
        logger.error("open(): IO Exception: ", ioException);
        connected = false;
    } catch (Exception exception) {
        logger.error("open(): Exception: ", exception);
        connected = false;
    }
}
Also used : SocketException(java.net.SocketException) InputStreamReader(java.io.InputStreamReader) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException)

Example 19 with SocketAddress

use of java.net.SocketAddress in project XobotOS by xamarin.

the class DatagramChannelImpl method receiveImpl.

private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException {
    SocketAddress retAddr = null;
    DatagramPacket receivePacket;
    int oldposition = target.position();
    int received = 0;
    // TODO: disallow mapped buffers and lose this conditional?
    if (target.hasArray()) {
        receivePacket = new DatagramPacket(target.array(), target.position() + target.arrayOffset(), target.remaining());
    } else {
        receivePacket = new DatagramPacket(new byte[target.remaining()], target.remaining());
    }
    do {
        received = IoBridge.recvfrom(false, fd, receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(), 0, receivePacket, isConnected());
        if (receivePacket != null && receivePacket.getAddress() != null) {
            if (received > 0) {
                if (target.hasArray()) {
                    target.position(oldposition + received);
                } else {
                    // copy the data of received packet
                    target.put(receivePacket.getData(), 0, received);
                }
            }
            retAddr = receivePacket.getSocketAddress();
            break;
        }
    } while (loop);
    return retAddr;
}
Also used : DatagramPacket(java.net.DatagramPacket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 20 with SocketAddress

use of java.net.SocketAddress in project tdi-studio-se by Talend.

the class DynamicsCRMClient method getProxy.

/**
     * Get the proxy setting if there is proxy for system
     */
private Proxy getProxy() {
    String proxyHost = System.getProperty("https.proxyHost");
    String proxyPort = System.getProperty("https.proxyPort");
    if (proxyHost != null) {
        int port = -1;
        if (proxyPort != null && proxyPort.length() > 0) {
            port = Integer.parseInt(proxyPort);
        }
        SocketAddress addr = new InetSocketAddress(proxyHost, port);
        Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
        return proxy;
    }
    return null;
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

SocketAddress (java.net.SocketAddress)717 InetSocketAddress (java.net.InetSocketAddress)542 Test (org.junit.Test)169 IOException (java.io.IOException)154 Socket (java.net.Socket)105 InetAddress (java.net.InetAddress)56 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)42 Proxy (java.net.Proxy)39 ArrayList (java.util.ArrayList)37 SocketChannel (java.nio.channels.SocketChannel)36 SocketException (java.net.SocketException)34 ServerSocket (java.net.ServerSocket)33 HashMap (java.util.HashMap)33 Channel (org.jboss.netty.channel.Channel)33 UnknownHostException (java.net.UnknownHostException)32 ByteBuffer (java.nio.ByteBuffer)32 Map (java.util.Map)31 Set (java.util.Set)31 Channel (io.netty.channel.Channel)30 HashSet (java.util.HashSet)30