Search in sources :

Example 26 with SocketException

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

the class LightwaveRfBinding method activate.

/**
     * Called by the SCR to activate the component with its configuration read
     * from CAS
     *
     * @param bundleContext
     *            BundleContext of the Bundle that defines this component
     * @param configuration
     *            Configuration properties for this component obtained from the
     *            ConfigAdmin service
     */
public void activate(final BundleContext bundleContext, final Map<String, Object> configuration) {
    String ipString = (String) configuration.get("ip");
    if (StringUtils.isNotBlank(ipString)) {
        LIGHTWAVE_IP = ipString;
    }
    String recieverPortsString = (String) configuration.get("receiveport");
    if (StringUtils.isNotBlank(recieverPortsString)) {
        LIGHTWAVE_PORTS_TO_RECEIVE_ON = Integer.parseInt(recieverPortsString);
    }
    String portTwoString = (String) configuration.get("sendport");
    if (StringUtils.isNotBlank(portTwoString)) {
        LIGHTWAVE_PORT_TO_SEND_TO = Integer.parseInt(portTwoString);
    }
    String sendRegistrationMessageString = (String) configuration.get("registeronstartup");
    if (StringUtils.isNotBlank(sendRegistrationMessageString)) {
        SEND_REGISTER_ON_STARTUP = Boolean.parseBoolean(sendRegistrationMessageString);
    }
    String sendDelayString = (String) configuration.get("senddelay");
    if (StringUtils.isNotBlank(sendDelayString)) {
        TIME_BETWEEN_SENT_MESSAGES_MS = Integer.parseInt(sendDelayString);
    }
    String okTimeoutString = (String) configuration.get("okTimeout");
    if (StringUtils.isNotBlank(okTimeoutString)) {
        TIMEOUT_FOR_OK_MESSAGES_MS = Integer.parseInt(okTimeoutString);
    }
    logger.info("LightwaveBinding: IP[{}]", LIGHTWAVE_IP);
    logger.info("LightwaveBinding: ReceivePort[{}]", LIGHTWAVE_PORTS_TO_RECEIVE_ON);
    logger.info("LightwaveBinding: Send Port[{}]", LIGHTWAVE_PORT_TO_SEND_TO);
    logger.info("LightwaveBinding: Register On Startup[{}]", SEND_REGISTER_ON_STARTUP);
    logger.info("LightwaveBinding: Send Delay [{}]", TIME_BETWEEN_SENT_MESSAGES_MS);
    logger.info("LightwaveBinding: Timeout for Ok Messages [{}]", TIMEOUT_FOR_OK_MESSAGES_MS);
    messageConvertor = new LightwaverfConvertor();
    try {
        wifiLink = new LightwaveRfWifiLink(LIGHTWAVE_IP, LIGHTWAVE_PORT_TO_SEND_TO, LIGHTWAVE_PORTS_TO_RECEIVE_ON, messageConvertor, TIME_BETWEEN_SENT_MESSAGES_MS, TIMEOUT_FOR_OK_MESSAGES_MS);
        wifiLink.addListener(this);
        wifiLink.start();
        if (SEND_REGISTER_ON_STARTUP) {
            wifiLink.sendLightwaveCommand(messageConvertor.getRegistrationCommand());
        }
        // Now the sender is started and we have sent the registration
        // message
        // start the Heat Poller
        heatPoller = new LightwaveRfHeatPoller(wifiLink, messageConvertor);
        // bindingChanged method
        for (LightwaveRfBindingProvider provider : providers) {
            Collection<String> itemNames = provider.getItemNames();
            registerHeatingPollers(provider, itemNames);
        }
    } catch (UnknownHostException e) {
        logger.error("Error creating LightwaveRFSender", e);
    } catch (SocketException e) {
        logger.error("Error creating LightwaveRFSender/Receiver", e);
    }
}
Also used : SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException) LightwaveRfBindingProvider(org.openhab.binding.lightwaverf.LightwaveRfBindingProvider)

Example 27 with SocketException

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

the class TCPMessageProcessor method run.

/**
     * Run method for the thread that gets created for each accept socket.
     */
public void run() {
    // Accept new connectins on our socket.
    while (this.isRunning) {
        try {
            synchronized (this) {
                // This is the default behavior.
                while (sipStack.maxConnections != -1 && this.nConnections >= sipStack.maxConnections) {
                    try {
                        this.wait();
                        if (!this.isRunning)
                            return;
                    } catch (InterruptedException ex) {
                        break;
                    }
                }
                this.nConnections++;
            }
            Socket newsock = sock.accept();
            if (sipStack.isLoggingEnabled()) {
                getSIPStack().getStackLogger().logDebug("Accepting new connection!");
            }
            // Note that for an incoming message channel, the
            // thread is already running
            incomingTcpMessageChannels.add(new TCPMessageChannel(newsock, sipStack, this));
        } catch (SocketException ex) {
            this.isRunning = false;
        } catch (IOException ex) {
            // Problem accepting connection.
            if (sipStack.isLoggingEnabled())
                getSIPStack().getStackLogger().logException(ex);
            continue;
        } catch (Exception ex) {
            InternalErrorHandler.handleException(ex);
        }
    }
}
Also used : SocketException(java.net.SocketException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 28 with SocketException

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

the class PlainDatagramSocketImpl method connect.

@Override
public void connect(InetAddress inetAddr, int port) throws SocketException {
    // Throws on failure.
    IoBridge.connect(fd, inetAddr, port);
    try {
        connectedAddress = InetAddress.getByAddress(inetAddr.getAddress());
    } catch (UnknownHostException e) {
        // here if the address is not resolvable
        throw new SocketException("Host is unresolved: " + inetAddr.getHostName());
    }
    connectedPort = port;
    isNativeConnected = true;
}
Also used : SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException)

Example 29 with SocketException

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

the class PlainSocketImpl method socksConnect.

/**
     * Connect using a SOCKS server.
     */
private void socksConnect(InetAddress applicationServerAddress, int applicationServerPort, int timeout) throws IOException {
    try {
        IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout);
    } catch (Exception e) {
        throw new SocketException("SOCKS connection failed", e);
    }
    socksRequestConnection(applicationServerAddress, applicationServerPort);
    lastConnectedAddress = applicationServerAddress;
    lastConnectedPort = applicationServerPort;
}
Also used : SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ErrnoException(libcore.io.ErrnoException) ConnectException(java.net.ConnectException)

Example 30 with SocketException

use of java.net.SocketException in project android_frameworks_base by ResurrectionRemix.

the class WifiDisplayController method getInterfaceAddress.

private static Inet4Address getInterfaceAddress(WifiP2pGroup info) {
    NetworkInterface iface;
    try {
        iface = NetworkInterface.getByName(info.getInterface());
    } catch (SocketException ex) {
        Slog.w(TAG, "Could not obtain address of network interface " + info.getInterface(), ex);
        return null;
    }
    Enumeration<InetAddress> addrs = iface.getInetAddresses();
    while (addrs.hasMoreElements()) {
        InetAddress addr = addrs.nextElement();
        if (addr instanceof Inet4Address) {
            return (Inet4Address) addr;
        }
    }
    Slog.w(TAG, "Could not obtain address of network interface " + info.getInterface() + " because it had no IPv4 addresses.");
    return null;
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Aggregations

SocketException (java.net.SocketException)925 IOException (java.io.IOException)349 InetAddress (java.net.InetAddress)254 NetworkInterface (java.net.NetworkInterface)240 UnknownHostException (java.net.UnknownHostException)153 Socket (java.net.Socket)146 SocketTimeoutException (java.net.SocketTimeoutException)118 ServerSocket (java.net.ServerSocket)114 DatagramSocket (java.net.DatagramSocket)95 Test (org.junit.Test)87 InetSocketAddress (java.net.InetSocketAddress)84 ArrayList (java.util.ArrayList)70 Inet4Address (java.net.Inet4Address)51 DatagramPacket (java.net.DatagramPacket)49 ConnectException (java.net.ConnectException)48 InputStream (java.io.InputStream)41 InterruptedIOException (java.io.InterruptedIOException)41 BindException (java.net.BindException)36 EOFException (java.io.EOFException)33 OutputStream (java.io.OutputStream)32