Skip to content

Commit

Permalink
Merge pull request #67 from ccutrer/listen_correct_interface
Browse files Browse the repository at this point in the history
fix a pairing issue
  • Loading branch information
andylintner authored Feb 12, 2019
2 parents 0788d47 + c1e558a commit 939c344
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/beowulfe/hap/HomekitServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HomekitServer {
*/
public HomekitServer(InetAddress localAddress, int port, int nThreads) throws IOException {
this.localAddress = localAddress;
http = new HomekitHttpServer(port, nThreads);
http = new HomekitHttpServer(localAddress, port, nThreads);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.beowulfe.hap.impl.HomekitWebHandler;
import com.beowulfe.hap.impl.http.HomekitClientConnectionFactory;
import java.net.InetAddress;
import java.util.concurrent.CompletableFuture;

public class HomekitHttpServer implements HomekitWebHandler {

private NettyHomekitHttpService service = null;
private final InetAddress localAddress;
private final int port;
private final int nThreads;

Expand All @@ -17,15 +19,16 @@ public void stop() {
}
}

public HomekitHttpServer(int port, int nThreads) {
public HomekitHttpServer(InetAddress localAddress, int port, int nThreads) {
this.localAddress = localAddress;
this.port = port;
this.nThreads = nThreads;
}

@Override
public CompletableFuture<Integer> start(HomekitClientConnectionFactory clientConnectionFactory) {
if (service == null) {
this.service = NettyHomekitHttpService.create(port, nThreads);
this.service = NettyHomekitHttpService.create(localAddress, port, nThreads);
return this.service.create(clientConnectionFactory);
} else {
throw new RuntimeException("HomekitHttpServer can only be started once");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.util.concurrent.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.CompletableFuture;
Expand All @@ -23,16 +24,18 @@ class NettyHomekitHttpService {

private static final Logger logger = LoggerFactory.getLogger(NettyHomekitHttpService.class);
private final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
private final InetAddress localAddress;
private final int port;
private final int nThreads;

public static NettyHomekitHttpService create(int port, int nThreads) {
return new NettyHomekitHttpService(port, nThreads);
public static NettyHomekitHttpService create(InetAddress localAddress, int port, int nThreads) {
return new NettyHomekitHttpService(localAddress, port, nThreads);
}

private NettyHomekitHttpService(int port, int nThreads) {
private NettyHomekitHttpService(InetAddress localAddress, int port, int nThreads) {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
this.localAddress = localAddress;
this.port = port;
this.nThreads = nThreads;
}
Expand All @@ -46,7 +49,7 @@ public CompletableFuture<Integer> create(HomekitClientConnectionFactory connecti
.childHandler(new ServerInitializer(connectionFactory, allChannels, nThreads))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
final ChannelFuture bindFuture = b.bind(port);
final ChannelFuture bindFuture = b.bind(localAddress, port);
bindFuture.addListener(
new GenericFutureListener<Future<? super Void>>() {

Expand Down

0 comments on commit 939c344

Please sign in to comment.