Search in sources :

Example 61 with SocketException

use of java.net.SocketException in project jcollectd by collectd.

the class UdpReceiver method listen.

public void listen(DatagramSocket socket) throws IOException {
    while (true) {
        byte[] buf = new byte[Network.BUFFER_SIZE];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);
        try {
            socket.receive(packet);
        } catch (SocketException e) {
            if (_isShutdown) {
                break;
            } else {
                throw e;
            }
        }
        parse(packet.getData());
    }
}
Also used : SocketException(java.net.SocketException) DatagramPacket(java.net.DatagramPacket)

Example 62 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 63 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseReadyEvent.

private void raiseReadyEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999" + rootPath + "/");
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 64 with SocketException

use of java.net.SocketException in project cw-omnibus by commonsguy.

the class WebServerService method raiseStartedEvent.

private void raiseStartedEvent() {
    ServerStartedEvent event = new ServerStartedEvent();
    try {
        for (Enumeration<NetworkInterface> enInterfaces = NetworkInterface.getNetworkInterfaces(); enInterfaces.hasMoreElements(); ) {
            NetworkInterface ni = enInterfaces.nextElement();
            for (Enumeration<InetAddress> enAddresses = ni.getInetAddresses(); enAddresses.hasMoreElements(); ) {
                InetAddress addr = enAddresses.nextElement();
                if (addr instanceof Inet4Address) {
                    event.addUrl("http://" + addr.getHostAddress() + ":4999");
                }
            }
        }
    } catch (SocketException e) {
        Log.e(getClass().getSimpleName(), "Exception in IP addresses", e);
    }
    EventBus.getDefault().removeAllStickyEvents();
    EventBus.getDefault().postSticky(event);
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 65 with SocketException

use of java.net.SocketException in project Openfire by igniterealtime.

the class RtpSocket method flushSocket.

public static void flushSocket(DatagramSocket socket) {
    /*
	 * Flush the socket
	 */
    int len = RtpPacket.getDataSize(RtpPacket.PCM_ENCODING, RtpPacket.MAX_SAMPLE_RATE, 2);
    len += RtpPacket.HEADER_SIZE;
    byte[] data = new byte[len];
    DatagramPacket packet = new DatagramPacket(data, len);
    int count = 0;
    try {
        socket.setSoTimeout(1);
        while (true) {
            try {
                socket.receive(packet);
                count++;
            } catch (SocketTimeoutException e) {
                break;
            } catch (IOException e) {
                Logger.println("Error flushing socket " + e.getMessage());
                break;
            }
        }
    } catch (SocketException e) {
        Logger.println("Can't flush receiver socket!");
    }
    if (count > 0) {
        if (Logger.logLevel >= Logger.LOG_MOREINFO) {
            Logger.println("Packets flushed:  " + count);
        }
    }
    try {
        socket.setSoTimeout(0);
    } catch (SocketException e) {
        Logger.println("Can't set socket timeout to 0!");
    }
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Aggregations

SocketException (java.net.SocketException)523 IOException (java.io.IOException)189 InetAddress (java.net.InetAddress)127 NetworkInterface (java.net.NetworkInterface)110 Socket (java.net.Socket)100 UnknownHostException (java.net.UnknownHostException)93 ServerSocket (java.net.ServerSocket)82 DatagramSocket (java.net.DatagramSocket)78 SocketTimeoutException (java.net.SocketTimeoutException)77 InetSocketAddress (java.net.InetSocketAddress)62 Test (org.junit.Test)50 ConnectException (java.net.ConnectException)39 DatagramPacket (java.net.DatagramPacket)38 ArrayList (java.util.ArrayList)35 BindException (java.net.BindException)31 Inet4Address (java.net.Inet4Address)24 SocketAddress (java.net.SocketAddress)24 InterruptedIOException (java.io.InterruptedIOException)23 IllegalBlockingModeException (java.nio.channels.IllegalBlockingModeException)23 SmallTest (android.test.suitebuilder.annotation.SmallTest)20