Пример #1
0
        public async Task ConnectAsync()
        {
            connection = new HubConnection(string.Format(url, "127.0.0.1", "8080"));
            hubProxy   = connection.CreateHubProxy("ChatHub");
            hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u));
            hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n));
            hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n));
            hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n));
            hubProxy.On <string, string>("BroadcastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("UnicastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string, string, string>("SetNewTask", (n, m, k) => SetNewTask?.Invoke(n, m, k));
            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }
        public async Task ConnectAsync()
        {
            string ipAdddresSett = ConfigurationManager.AppSettings["ipAddress"];
            int    ipPortSett    = Int32.Parse(ConfigurationManager.AppSettings["ipPort"]);

            connection = new HubConnection(string.Format(url, ipAdddresSett, ipPortSett));
            hubProxy   = connection.CreateHubProxy("ChatHub");
            hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u));
            hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n));
            hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n));
            hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n));
            hubProxy.On <string, string>("BroadcastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("UnicastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string, string, string>("SetNewTask", (n, m, k) => SetNewTask?.Invoke(n, m, k));
            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }