2881099 / FreeIM

.NETCore websocket 实现简易、高性能、集群即时通讯组件,支持点对点通讯、群聊通讯、上线下线事件消息等众多实用性功能.
MIT License
1.42k stars 418 forks source link

关于wss 协议的发布 #22

Closed lauralxj closed 4 years ago

lauralxj commented 4 years ago

目前看到是ws 的,如果单独部署imserver , 如何配置证书呢?示例代码中不支持下图参数 网络图片 期待回复,谢谢!

2881099 commented 4 years ago

https://github.com/2881099/im/issues/11

2881099 commented 4 years ago

https://github.com/2881099/im/issues/3

2881099 commented 4 years ago

wss 他 imcore im 没有绑定关系,wss 参考 https aspnetcore 配置的教程就好了。

lauralxj commented 4 years ago

谢谢回复 现在的场景如下: 1.终端是小程序 2.web api 是.net framework 4.5 3.按照昨天您提示的我发布了ImServer.exe 4.IP连接没有问题,ImServer.exe 这怎么绑定域名啊,感谢

2881099 commented 4 years ago

ImServer.exe 这怎么绑定域名

    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel(option=> {
                    option.UseHttps("server.pfx", "linezero");
                })
                .UseUrls("https://www.baidu.com:443")
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
2881099 commented 4 years ago

websocket 不限制端口号,小程序可以用 wss://www.baidu.com:6001 连接

2881099 commented 4 years ago
            .UseKestrel(option=> {
                option.UseHttps("server.pfx", "linezero");
            })
            .UseUrls("https://www.baidu.com:443")

这两个配置是关键,其他资料可以到百度搜索:aspnetcore https 配置

lauralxj commented 4 years ago

可以理解为把ImServer下的Program文件增加

.UseKestrel(option=> {

            option.UseHttps("server.pfx", "linezero");
        })
        .UseUrls("https://www.baidu.com:443")'

如上代码,ImServer可以部署在iis上,由iIS承载吗?

2881099 commented 4 years ago

不用挂载,独立运行

lauralxj commented 4 years ago

搞不定,崩溃:

Startup.cs app.UseImServer(new ImServerOptions { Redis = new CSRedis.CSRedisClient("127.0.0.1:6379,poolsize=5"), Servers = new[] { "39.243.73.68:8080" }, Server = "39.243.73.68:8080" });

Program.cs WebHost.CreateDefaultBuilder(args) .UseKestrel(options => { options.Listen(IPAddress.Loopback, 8080, listenOptions => { listenOptions.UseHttps("message.pfx", "9874321"); }); }) .UseUrls("https://www.baidu.com:8080") .UseStartup<Startup>(); 预连接代码,ws调整为wss public string PrevConnectServer(Guid clientId, string clientMetaData) { var server = SelectServer(clientId); var token = $"{Guid.NewGuid()}{Guid.NewGuid()}{Guid.NewGuid()}{Guid.NewGuid()}".Replace("-", ""); _redis.Set($"{_redisPrefix}Token{token}", JsonConvert.SerializeObject((clientId, clientMetaData)), 10); return $"wss://{server}{_pathMatch}?token={token}"; } 结果报错如下:

以一种权限不允许的方式做了一个访问套接字的尝试 网上说是端口占用的问题,更改后依然报此错误。 期待帮助,谢谢!

2881099 commented 4 years ago

实在弄不好的话,就用 http 转发吧,把其他 https 的服务器转发给这里。就不用在这里配置 ssl 了

2881099 commented 4 years ago

方便留个交流方式或者建个群不,付费指导也行啊,发了二天时间了搞不定,今天才发现API获取ws url后根本连接不上。 QQ:18477899

加你了,等通过

lauralxj commented 4 years ago

结贴,在作者的远程指导下终于连线成功,抽时间整理一下发出来,避免其它使用者再走弯路,感谢!