首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSockets WSS不连接

XSockets WSS不连接
EN

Stack Overflow用户
提问于 2014-07-28 10:35:31
回答 1查看 508关注 0票数 0

我很难实现WSS。我在IIS7上做了一个自我签名的证书。我已经尝试过几次通过JS连接,但它根本不会。更令人费解的是,非安全的实现工作得非常好。

我的服务器代码如下:

代码语言:javascript
复制
         public class SSLConfig : ConfigurationSetting
        {
            public SSLConfig()
                : base("wss://localhost:4509")
            {
                this.CertificateLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
                this.CertificateSubjectDistinguishedName = "cn=localhost";
            }
        }

    class Program
        {
            static void Main(string[] args)
            {
                var myCustomConfigs = new List<IConfigurationSetting>();
                myCustomConfigs.Add(new SSLConfig());

                using (var server = Composable.GetExport<IXSocketServerContainer>())
                {
                    Console.WriteLine("running");
                    server.StartServers(configurationSettings: myCustomConfigs);
                    foreach (var serv in server.Servers)
                    {
                        Console.WriteLine(serv.ConfigurationSetting.Endpoint);
                    }
                    Console.ReadLine();
                    server.StopServers();
                }
            }
        }

 public class TestSockets : XSocketController
    {      
        public TestSockets()
        {
        }

        public void Echo(string message)
        {
            this.Send(new
            {
                Message = message
            }.AsTextArgs("message"));
        }
}

Javascript:

代码语言:javascript
复制
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script src="\scripts\XSockets.latest.js"></script>
  <script>
    var ws;
    $(function () {
      ws = new XSockets.WebSocket("wss://localhost:4509/TestSockets");

      ws.on(XSockets.Events.open, function (clientInfo) {
        alert(clientInfo);
        console.log('Open', clientInfo);
      });

      ws.on(XSockets.Events.onError, function (err) {
        alert(err);
        console.log('Error', err);
      });

      $("#btnSocket").on("click", function () {
        ws.publish("Echo", { message: XSockets.Utils.randomString(50) });
      });
    });
  </script>
</head>
<body>
<input type="button" value="click" id="btnSocket"/>
</body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-28 15:26:27

事实证明,由于使用了自签名证书,Firefox在试图建立连接时抛出了一个错误(Chrome只是保持沉默.)。

在使用https://而不是wss://访问URI之后,我能够在所有浏览器上添加异常,现在我可以连接到wss服务器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24993377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档