Skip to content

Commit

Permalink
Bind WebcamStreamer server socket to 0.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Nov 10, 2017
1 parent 3876d3c commit 6a47494
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
Expand Down Expand Up @@ -40,7 +41,7 @@ private class Acceptor implements Runnable {

@Override
public void run() {
try (ServerSocket server = new ServerSocket(port)) {
try (ServerSocket server = new ServerSocket(port, 50, InetAddress.getByName("0.0.0.0"))) {
while (started.get()) {
executor.execute(new Connection(server.accept()));
}
Expand All @@ -63,9 +64,9 @@ public void run() {

LOG.info("New connection from {}", socket.getRemoteSocketAddress());

BufferedReader br = null;
BufferedOutputStream bos = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
final BufferedReader br;
final BufferedOutputStream bos;
final ByteArrayOutputStream baos = new ByteArrayOutputStream();

try {
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Expand Down Expand Up @@ -149,8 +150,12 @@ public void run() {
LOG.debug("Connection to client is closed");
}

br.close();
bos.close();
try {
br.close();
bos.close();
} catch (SocketException se) {
LOG.debug("Exception when closing socket", se);
}

LOG.debug("Socket exception from " + socket.getRemoteSocketAddress(), e);

Expand Down Expand Up @@ -185,17 +190,20 @@ public void run() {
}

} finally {

LOG.info("Closing connection from {}", socket.getRemoteSocketAddress());

for (Closeable closeable : new Closeable[] { br, bos, baos }) {
try {
closeable.close();
} catch (IOException e) {
LOG.error("Cannot close socket", e);
LOG.debug("Cannot close socket", e);
}
}
try {
socket.close();
} catch (IOException e) {
LOG.error("Cannot close socket", e);
LOG.debug("Cannot close socket", e);
}
}
}
Expand Down

0 comments on commit 6a47494

Please sign in to comment.