我已经创建了asp.net core
-signalr app
。
它托管在IIS上,这是URL:
https://192.168.1.167/javasignalr/
信令中心在此地址上:
https://192.168.1.167/javasignalr/signaling
我测试了该应用程序,signalr
正常工作,即连接已启动,并且从信令中心到UI都得到了结果。
此后,我创建了一个新的android项目,并遵循了官方的docs
因此,在我的Andoid项目中,MainActivity
中有以下内容:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
HubConnection hubConnection = HubConnectionBuilder.create("https://192.168.1.167/javasignalr/signaling").build();
hubConnection.on("newMessage", (message) -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This is Title");
builder.setMessage("This is message for Alert Dialog");
builder.setPositiveButton("Positive Button", (dialog, which) -> onBackPressed());
builder.setNegativeButton("Negative Button", (dialog, which) -> dialog.cancel());
builder.show();
}, String.class);
hubConnection.start();
}
但是在调试时,我看到hubConnection
的状态是:
disconnected
任何想法为什么会发生,以及如何建立连接:
android客户端<-> iis dotnet核心应用