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);
}
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations