Solution au problème selon lequel le serveur de déploiement WebSocket ne peut pas se connecter au réseau externe

黄舟
Libérer: 2017-09-26 10:40:56
original
3885 Les gens l'ont consulté

La première chose que je veux dire est le problème que j'ai rencontré :

<span class="typ">WebSocket<span class="pln"> la connexion à <span class="str">'ws://www.xxxx.com/xxx/xx'<span class="pln"> a échoué<span class="pun"> :<span class="pln "> Erreur<span class="pln"> lors de <span class="typ">WebSocket<span class="pln"> poignée de main<span class="pun"> :<span class="pln "> <span class="typ">Code de réponse<span class="pln"> inattendu<span class="pun"> :<span class="pln"> <span class="lit">200 <br>Le site web est lié au serveur, et il est possible d'accéder au service webSocket directement sur le serveur. Cependant, lorsque j'utilise le réseau externe pour y accéder, cette erreur est mon plus grand ennemi que j'ai rencontré. des voleurs avant, et je peux facilement le résoudre. , n'en parlons plus, affrontons directement le patron<br><br>J'ai passé deux après-midi à chercher une solution, mais je ne l'ai pas trouvée. mais en décrivant directement ce problème en utilisant .NET, cela n'a pas fonctionné. Pas beaucoup, mais beaucoup d'amis ont été confrontés à ce problème. <br>Cela n'a rien à voir avec des problèmes de navigateur. Je l'ai testé avec Firefox, Google et IE, et les problèmes attendus surviennent toujours. <br>Plateforme de développement : .NET, utilisez ASP.NET MVC pour créer le site Web<code><span class="typ">WebSocket<span class="pln"> connection to <span class="str">'ws://www.xxxx.com/xxx/xx'<span class="pln"> failed<span class="pun">:<span class="pln"> <span class="typ">Error<span class="pln"> during <span class="typ">WebSocket<span class="pln"> handshake<span class="pun">:<span class="pln"> <span class="typ">Unexpected<span class="pln"> response code<span class="pun">:<span class="pln"> <span class="lit">200<br>网站绑定到了服务器,直接在服务器上访问webSocket服务是可行的,但是当我用外网访问时,这个错误就是我最大的敌人,在这之前还遇到过几个小毛贼,可以轻松解决,不再提,直面boss吧<br><br>花费两个下午的时间寻找解决方案,但是并没有找到,各种解决方案,但是直接来描述.NET下使用这一问题的,却是不多,然而面对了这一问题的朋友,大把的有。<br>这个无关浏览器问题,我有火狐,谷歌,IE测试过,该出的问题还是会有。<br>开发平台:.NET,利用ASP.NET MVC搭建网站</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit">,在其中利用WebSocket服务,目的是在网站内设计一个讨论平台。<br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"><span style="font-size: 15px"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> <span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun "> <span class="pln"><span class="lit">, qui utilise le service WebSocket dans le but de concevoir une plateforme de discussion au sein du site Web. <br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"><span style="font-size: 15px"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> 具体来说一说:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="typ"><span class="pln"><span class="str"><span classe="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class=" pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"></span><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span classe="jeu de mots"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class=" jeu de mots"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span classe="pln"><span class="lit"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span classe="lit">Pour être précis : <p class="lang-java prettyprint prettyprinted"><span style="font-size: 15px"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span classe="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"><span style="font-size: 15px"><code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span classe="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> <span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit">首先,看下我的网页代码</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit">:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>


<script type="text/javascript">
        $(function () {            
        var url = "ws://xxxx:xx"+"@Url.Action("RequestProcessCenter")";            
        var ws;            
        function connect() {
                ws = new WebSocket(url);
                $("#TopicContent").append("正在连接\n");
                ws.onopen = function () {
                    $("#TopicContent").append("已经连接\n");
                };
                ws.onmessage = function (evt) {
                    console.log(evt.data);
                    $("#TopicContent").append(evt.data);
                };
                ws.onclose = function () {
                    $("#TopicContent").append("已经关闭\n");
                };
                ws.onerror = function (evt) {
                    console.log(evt.data);
                    $("#TopicContent").append(evt.data);
                };
            };
            $("#send").click(function () {
                console.log(1);
                console.log(ws.readyState);
                console.log(WebSocket.OPEN);                
                if (ws.readyState == WebSocket.OPEN) {
                    ws.send($("#content").val());
                    $(this).val("");
                }                else {
                    $("#TextMessge").append("连接已经关闭");
                }
            });
            $("#open").click(function () {
                connect();
            });
            $("#close").click(function () {
                ws.close();
            });
        });    </script>
Copier après la connexion



public void RequestProcessCenter()
        {            if (HttpContext.IsWebSocketRequest)
            {                var currUser = GetCurrUser();                
            this._UserName = currUser.LoginName;
                HttpContext.AcceptWebSocketRequest(ProcessTopic);
            }            else
            {
                HttpContext.Response.Write("请求失败哟");
            }
        }
Copier après la connexion

<span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pun"><span classe="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class=" pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit">首先,看下我的网页代码</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="jeu de mots"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span class="pun "><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span class="pln"><span class="lit"> :<p><br><br><br></p> <p><br></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p>后台代码: webSocket所要求的url格式我想应该是不会配错。错误显示如图: 返回200,尽管是请求成功了,  请求方式也确实是websocket了,这是为什么呢?查询了很多资料,但是并没有发现真正解决这一问题的,或许是我找的方式有问题,但是百度前三页我是看了,并没有想要的解决方案。自己动手,做了个测试, Il s'agit d'un système WebSocket.用和网站绑定的同一端口呢?经过该测试: 1.本地80端口绑定域名 webSocket利用域名,端口80 无效 2.本地80端口绑定域名 webSocket利用2017端口 主机地址用服务器ip地址 有效 3. Version 2017 de la version webSocket des années 80 Version  4. Version 2017 de la version webSocket version 2017效总结 80端口可能受系统限制另一方面:域名绑定是否会影响 没有测试 成功解决了外网虽返回200却不能使用websocket服务的问题。这种情况下需要注意的是, Il s'agit d'un système IIS qui fonctionne avec WebSocket et WebSocket.个网站可以使用同一个程序版本,我就是这么做的,没有什么好的想法,菜鸟级人物。 这个网站介绍了WebSocket的一些知识,以及websocket默认使用80-433端口,或许我在想,是不是我网站绑定的端口和websocket绑定相同端口时,外网请求就是此时出的错呢,这个问题也一时半会不能深究,暂时性的功能是达到了,但是感觉只能是说满足了需求,却不能简化需求过程。 留下一个猜想,我在服务器上访问时,是可行的,都是使用80端口,websocket服务能够正常使用,那是因为在服务器上发起时、 Il s'agit d'une application WebSocket, d'une application WebSocket et d'une application WebSocket.防火墙识别出问题。 </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!