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