0

私はwinformデスクトップアプリを持っています。signalr.client を参照し、サーバーへの接続を開始しました。connection_stateChanged() イベントで接続メッセージを受け取ります。

私の困難はこれです: サーバーコードのどこにクライアント接続をトラップ/追加しますか? クライアント接続を追加する必要があり、その接続 ID に固有のディレクトリに fileSystemWatcher を配置するつもりでした。次に、ファイルが(サーバー上に)入ってきたら、.netクライアントにこのファイルを通知したいと思いました。完了したら、クライアントが再接続して、同じ基準でメッセージをさらに受信するようにします。

これは私がこれまでに持っているものです:

[ServerCode] Global.asax.cs ページ:

  protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapConnection<ClientListener>("echo", "/echo");
    }

私の App_code フォルダー内のクラスで:

[

HubName("MotionIQ")]
public class ClientListener : Hub
{
    static ConcurrentDictionary<string, string> dic = new ConcurrentDictionary<string, string>();

    public void Send(string name, string message)
    {
        // Call the broadcastMessage method to update clients.
        Clients.All.broadcastMessage(name, message);
    }

    public void sendToSpecific(string name, string message, string to)
    {
        // Call the broadcastMessage method to update clients.
        Clients.Caller.broadcastMessage(name, message);
        Clients.Client(dic[to]).broadcastMessage(name, message);
    }

    public void Notify(string name, string id)
    {
        if (dic.ContainsKey(name))
        {
            Clients.Caller.differentName();
        }
        else
        {
            dic.TryAdd(name, id);

            foreach (KeyValuePair<String, String> entry in dic)
            {
                Clients.Caller.online(entry.Key);
            }

            Clients.Others.enters(name);
        }
    }

    public override Task OnDisconnected()
    {
        var name = dic.FirstOrDefault(x => x.Value == Context.ConnectionId.ToString());
        string s;
        dic.TryRemove(name.Key, out s);
        return Clients.All.disconnected(name.Key);
  }

[私の .net c# デスクトップ クライアント アプリで]

public void Init(bool _isLocal)
{
    var connection = new Connection("http://www.informedmotion.co.uk:12722/echo");//MotionIQ");
    connection.Received += new Action<string>(connection_Received);
    connection.StateChanged += new Action<StateChange>(connection_StateChanged);
    // Start the connection
    connection.Start().Wait();
    string line = null;
    while ((line = Console.ReadLine()) != null)
    {
        // Send a message to the server
        connection.Send(line).Wait();
    }
}
void connection_StateChanged(StateChange obj)
{

}

void connection_Received(string obj)
{

}

私はほとんどそこにいますか、それとも完全に間違ったことをしていますか?

4

1 に答える 1