我有一个对话框生成器的代码:
public void showServerTerminalServerFoundDialog(final NsdServiceInfo serverServiceInfo){
new AlertDialog.Builder(mainActivity)
.setCancelable(false)
.setMessage(R.string.dialog_server_already_running_message)
.setPositiveButton(R.string.continue_as_server, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
closeOtherServerApp(serverServiceInfo);
createServerTerminal(getTerminalId());
isRunning = false;
instance = null;
stopService();
init(mainActivity);
createServerTerminal(getTerminalId());
mainActivity.onDestroy();
transferServerControl(serverServiceInfo);
dialog.dismiss();
}
})
.setNeutralButton(R.string.become_a_client, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.i("NetworkService","Al clicar crea una terminal de cliente y hago dismiss");
serverCreateClientTerminal(serverServiceInfo);
dialog.dismiss();
}
})
.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.i("NetworkService","El usuario sale");
mainActivity.userExit();
dialog.dismiss();
}
})
.show();
}
有时,当我运行该应用程序时,服务器状态从上次开始就没有变化,并且总是像服务器一样分配。
我尝试通过肯定按钮转移服务器控件,但是当我运行该应用程序时,出现另一个对话框,告诉我,我无法转移服务器控件。
编辑: 查看应用程序的运行,我单击对话框生成器的正按钮,并得到ECONNREFUSED错误。 这是getSocket的代码:
protected Socket getSocket() throws IOException {
if (serverNsdServiceInfo == null) {
serverNsdServiceInfo = networkService.getServerNsdServiceInfo();
}
if (serverNsdServiceInfo == null) {
throw new IOException("Server connection lost.");
}
return new Socket(serverNsdServiceInfo.getHost(), serverNsdServiceInfo.getPort());
}
我在return语句中收到错误,这可能是导致套接字的未关闭属性?希望你的答案