在signalr中如何实现一对一聊天 [英] In signalr how do I implement one to one chat

查看:537
本文介绍了在signalr中如何实现一对一聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以进行多次聊天,但无法将其处理为一对一。请你帮我找一下。有时我没有找到建立代理的连接。连接它需要什么脚本。?



我尝试过:



i am able to do multi chating but unable to process it to one to one. please can u help me to find. and sometimes i dont find connection establishing to proxy. what scripts aree required to connect it.?

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sample.Models;
 

namespace Sample.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Chat()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Chat(string message)
        {
            if (OnlineUser.lobj.Where(i => i.sessionId == System.Web.HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value.ToString()).Count() > 0)
                OnlineUser.ADDusers("", System.Web.HttpContext.Current.Session["UserName"].ToString(),  System.Web.HttpContext.Current.Session["UserId"].ToString(), System.Web.HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value.ToString());
            //hdnUserId.Value = Session["UserId"].ToString();
            //hdnUserName.Value = Session["UserName"].ToString();
            {

            }
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}







==模型类

==




==model class
==

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Sample.Models
{
    public static class OnlineUser
    {
        public static List<UserModal> lobj= new List<UserModal>();

        public static void ADDusers(string strconnectionId, string struserName, string struserId, string strsessionId)
        {
            UserModal uobj = new UserModal();
            uobj.connectionId = strconnectionId;
            uobj.userName = struserName;
            uobj.userId = struserId;
            uobj.newStatus=true;
            uobj.sessionId = strsessionId;
            lobj.Add(uobj);
        }
    }
}

推荐答案

查看本文中的私人聊天部分 Asp.Net SignalR聊天室 [ ^ ]
Check out the private chat section in this article Asp.Net SignalR Chat Room[^]


HEllo,



请查看以下链接。我曾尝试过同样的方法。

[ ^ ]



谢谢
HEllo ,

Please have a look at the below link. I had tried the same.
[^]

Thank You


这篇关于在signalr中如何实现一对一聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆