首页 新闻 会员 周边

websocket 服务器启动如果三天内未触发握手,再次进行调用send方法失败。

0
悬赏园豆:10 [已解决问题] 解决于 2021-11-16 14:45

websocket 服务器启动如果三天内未触发握手,再次进行调用send方法失败。。用的是c#的fleck。详细错误信息:2021-10-28 11:50:59:websocket错误异常:未将对象引用设置到对象的实例。目前在线数量为:0;详情错误信息:无
发送代码方法如下:
public static void Send(string groupName, string groupValue, string res)
{

        int cc = 0;
        try
        {
            LogHelper.InputLog("步骤1");
            var sockets = allSockets.Where(x => x.GroupName == groupName && x.GroupValue == groupValue);
            if (sockets == null || sockets.Count() <= 0)
            {
                LogHelper.InputLog("步骤4");
            }

            LogHelper.InputLog("步骤2");
            cc = sockets.Count();
            if (cc > 0)
            {
                LogHelper.InputLog("步骤3");
                foreach (var item in sockets.ToList())
                {
                    if (item.Socket != null)
                    {
                        item.Socket.Send(res);
                        LogHelper.InputLog("消息发送成功:" + res + "用户地址:" + item.Socket.ConnectionInfo.ClientIpAddress);
                    }
                    else
                    {
                        LogHelper.InputLog("步骤5");

                    }
                }
            }
            else
            {
                LogHelper.InputLog("无人连接,发送失败!groupname:" + groupName + ";groupValue:" + groupValue + ";参数:" + res);
            }
        }
        catch (Exception ex)
        {
            var ss = "无";
            if (ex.InnerException != null)
                ss = ex.InnerException.ToString();
            LogHelper.InputLog("websocket错误异常:" + ex.Message + "目前在线数量为:" + cc + ";详情错误信息:" + ss);
            throw;
        }
    }
CoolDog;的主页 CoolDog; | 初学一级 | 园豆:194
提问于:2021-11-04 09:42

没有人吗?。。我感觉是iis的问题。 因为我实在想不到代码有何问题。

CoolDog; 2年前

强烈感觉是被iis给回收了 导致的 !!!

CoolDog; 2年前
< >
分享
最佳答案
0

谢谢大家,关注。问题已经找到,是因为list集合中存在null的对象导致了where方法报错!感谢大家。

CoolDog; | 初学一级 |园豆:194 | 2021-11-09 10:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册