Skip to content

Commit

Permalink
Do not specify IP address.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanzhenjie committed Mar 7, 2020
1 parent 1c76822 commit 1eb2f4e
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.yanzhenjie.andserver.Server;
import com.yanzhenjie.andserver.sample.util.NetUtils;

import java.net.InetAddress;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -37,14 +38,13 @@ public class CoreService extends Service {
@Override
public void onCreate() {
mServer = AndServer.serverBuilder(this)
.inetAddress(NetUtils.getLocalIPAddress())
.port(8080)
.timeout(10, TimeUnit.SECONDS)
.listener(new Server.ServerListener() {
@Override
public void onStarted() {
String hostAddress = mServer.getInetAddress().getHostAddress();
ServerManager.onServerStart(CoreService.this, hostAddress);
InetAddress address = NetUtils.getLocalIPAddress();
ServerManager.onServerStart(CoreService.this, address.getHostAddress());
}

@Override
Expand Down Expand Up @@ -76,12 +76,7 @@ public void onDestroy() {
* Start server.
*/
private void startServer() {
if (mServer.isRunning()) {
String hostAddress = mServer.getInetAddress().getHostAddress();
ServerManager.onServerStart(CoreService.this, hostAddress);
} else {
mServer.startup();
}
mServer.startup();
}

/**
Expand Down

0 comments on commit 1eb2f4e

Please sign in to comment.