Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Signalr signar客户端方法在hub.start()之前绑定,但在服务器方法之后未被调用_Signalr - Fatal编程技术网

Signalr signar客户端方法在hub.start()之前绑定,但在服务器方法之后未被调用

Signalr signar客户端方法在hub.start()之前绑定,但在服务器方法之后未被调用,signalr,Signalr,我可以在我的服务器方法上设置一个断点,并在集线器启动时调用它。如果我将断点放在hub.start()上,我会看到该连接已经绑定了该方法的客户端版本。但不知何故,该方法并没有从服务器调用。这是我的密码: 服务器方法 [HubName("MovementHub")] public class MovementHub : Hub { public void UpdatePlayerPosServer(PlayerPosition playerPosition) { p

我可以在我的服务器方法上设置一个断点,并在集线器启动时调用它。如果我将断点放在hub.start()上,我会看到该连接已经绑定了该方法的客户端版本。但不知何故,该方法并没有从服务器调用。这是我的密码:

服务器方法

 [HubName("MovementHub")]
public class MovementHub : Hub
{
    public void UpdatePlayerPosServer(PlayerPosition playerPosition)
    {
        playerPosition.LastUpdatedBy = Context.ConnectionId;
        Clients.AllExcept(playerPosition.LastUpdatedBy).updatePlayerPosClient(playerPosition); //debugging here shows the playerposition all filled out nicely. this hub method is HIT.
    }
}
$(() => {

var connection = (<any>$.connection).MovementHub; 

    //this method is never called
   connection.client.updatePlayerPosClient = (playerPosModel) => {
        alert("updatingremotePlayers: " + playerPosModel);            
    }

});
客户端方法

 [HubName("MovementHub")]
public class MovementHub : Hub
{
    public void UpdatePlayerPosServer(PlayerPosition playerPosition)
    {
        playerPosition.LastUpdatedBy = Context.ConnectionId;
        Clients.AllExcept(playerPosition.LastUpdatedBy).updatePlayerPosClient(playerPosition); //debugging here shows the playerposition all filled out nicely. this hub method is HIT.
    }
}
$(() => {

var connection = (<any>$.connection).MovementHub; 

    //this method is never called
   connection.client.updatePlayerPosClient = (playerPosModel) => {
        alert("updatingremotePlayers: " + playerPosModel);            
    }

});
$(()=>{
var connection=($.connection).MovementHub;
//永远不会调用此方法
connection.client.updatePlayerPosClient=(playerPosModel)=>{
警报(“更新RemotePlayer:+playerPosModel”);
}
});
集线器启动(typescript类。方法从另一个类调用)

public updateServerPos=(x:number,y:number)=>{
var connection=($.connection).MovementHub;
this.LoginID=$(“#displayname”).val();
$.connection.hub.start().done(()=>{
var playerposModel={Id:this.LoginID,X:X,Y:Y};
connection.server.updatePlayerPosServer(playerposModel);//这里的调试告诉我,“connection”此时绑定了客户机方法
}).失败(功能(错误){
console.log(错误);
});
}
我已经阅读了一些关于这方面的文章,其中指定在hub启动之前必须绑定客户机方法,但事实并非如此。并且服务器方法被正确调用。所以我不知道这里发生了什么

编辑:我意识到,我是个白痴,可能会被客户的“AllExcept”呼叫跳过。我是个例外!哈哈


onw唯一剩下的问题是为什么我必须在IFFE中“实例化”客户机方法?我想把它放在调用服务器方法的同一个Typescript类中。

结果表明,混合使用javascript IIFE调用和Typescript调用可能会很危险。在绑定这个客户机方法之前,我有一个完全不相关(我认为)的中心开始发生。我意识到,即使我有两个集线器,实际上只有一个集线器;我真傻