无法将android signalr与服务器连接

时间:2017-11-03 11:46:33

标签: android signalr signalr-hub signalr.client

我想将SignalR android客户端与服务器连接。我搜索太多,但无法解决我的问题我是signalR的新手,所以请任何人告诉我解决方案。我得到了以下异常

java.util.concurrent.ExecutionException: microsoft.aspnet.signalr.client.transport.NegotiationException: There was a problem in the negotiation with the server

这是我的代码

服务器端

aspx文件

var IWannaChat = $.connection.myChatHub;


        $.connection.hub.start().done(function () {
            console.log("id : %o", $.connection.hub.id);

                document.getElementById("connectionid").innerHTML =
                "Name: " + $('#displayname').val() +
                "<br/> Connection ID: " + $.connection.hub.id;

                    }

.cs文件

[HubName("myChatHub")]
public class LetsChat : Hub
{

    public override Task OnConnected()
    {

        System.Diagnostics.Debug.WriteLine("Connected");

        return base.OnConnected();
    }


    public override Task OnDisconnected()
    {

        System.Diagnostics.Debug.WriteLine("Disconnected");

        return base.OnDisconnected();
    }

Android代码

Platform.loadPlatformComponent(new AndroidPlatformComponent());

    String serverUrl = "http://192.168.100.72/Chat.aspx";
    mHubConnection = new HubConnection(serverUrl);
    String SERVER_HUB_CHAT = "myChatHub";
    mHubProxy = mHubConnection.createHubProxy(SERVER_HUB_CHAT);
    ClientTransport clientTransport = new ServerSentEventsTransport(mHubConnection.getLogger());
    SignalRFuture<Void> signalRFuture = mHubConnection.start(clientTransport);

    try {
        signalRFuture.get();
    } catch (InterruptedException | ExecutionException e) {
        Log.e("SimpleSignalR Exception", e.toString());
        return;
    }


    mHubConnection.connected(new Runnable() {

        @Override
        public void run() {
            Global.displayLog("SignalR_connection Connected connection_Id " + mHubConnection.getConnectionId() + " ConnectionToken" +
                    mHubConnection.getConnectionToken());
            //  Toast.makeText(SignalRService.this,"Connected",Toast.LENGTH_SHORT).show();
        }
    });

请帮助我双方都做错了

0 个答案:

没有答案