먼저 말씀드리고 싶은 것은 제가 직면한 문제입니다:
<span class="typ">WebSocket<span class="pln"> <span class="str">'에 대한 연결 ws:/ /www.xxxx.com/xxx/xx'<span class="pln"> 실패<span class="pun">:<span class="pln"> <span class="typ">오류WebSocket<span class="pln"> 핸드셰이크 중 <span class="pun">:<span class="pln"> <span class="typ">예기치 않은<span class="pln">응답 코드<span class="pun">:<span class="pln"> <span class="lit">200<br>웹사이트가 서버에 바인딩되어 있으며 webSocket 서비스는 가능하지만 외부 네트워크를 사용하여 액세스할 때 이 오류가 가장 큰 적입니다. 이전에 몇 가지 작은 도둑을 만났기 때문에 더 이상 쉽게 해결할 수 없습니다. 상사와 직접 대면<br> <br>이틀 동안 해결책을 찾았지만 찾을 수 없었습니다. 다양한 해결책이 있지만 .NET을 사용하여 이 문제를 직접 설명하는 사람은 많지 않습니다. 나는이 문제에 직면했습니다. 친구들이 많이 있습니다. <br>브라우저 문제와는 관련이 없습니다. Firefox, Google, IE에서 테스트해 보았는데 예상했던 문제가 여전히 발생합니다. <br>개발 플랫폼: .NET, ASP.NET MVC를 사용하여 웹사이트 구축<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"><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="pun"><span class="pln"><span class="lit">. <br>🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜</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">🎜<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="pun"><span class="pln"><span class="typ"><span class="pln"><span class="pun"><span><span class="lit">🎜<code><span class="typ"><span class="pln"><span class="str"><span class="pln"><span class="pln"><span class="typ"><span class="pln"><span class="typ"><span class="pln"><span><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 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"><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="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>
<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="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="lit">首先,看下我的网页代码<p><br></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
🎜🎜<span class="pln"><span class="str"><span class="pln"><span class="pun"><span class="pln"><span><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>
🎜🎜🎜🎜🎜<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>
public void RequestProcessCenter() { if (HttpContext.IsWebSocketRequest) { var currUser = GetCurrUser(); this._UserName = currUser.LoginName; HttpContext.AcceptWebSocketRequest(ProcessTopic); } else { HttpContext.Response.Write("请求失败哟"); } }
위 내용은 WebSocket 배포 서버가 외부 네트워크에 연결되지 않는 문제 해결의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!