WebSocket deployment: unable to connect to the Internet of the server solution, websocket deployment

Source: Internet
Author: User

WebSocket deployment: unable to connect to the Internet of the server solution, websocket deployment

 

The first thing I need to talk about is the problem I encountered:

WebSocket connection to 'ws: // www.xxxx.com/xxx/xx' failed: Error during WebSocket handshake: Unexpected response code: 200
It is feasible to bind a website to the server and directly access the webSocket service on the server. However, when I access the website over the Internet, this error is my biggest enemy. Before that, I have met several thieves, it can be easily solved. Don't mention it again. Face boss.

It took two afternoons to find a solution, but it was not found. Various solutions were described directly. NET, but there are not many friends who face this problem.
This has nothing to do with browser problems. I have tested Firefox, Google, and IE, and the problem still persists.
Development Platform:. NET, using ASP. net mvc to build a website
The purpose of using the WebSocket service is to design a discussion platform on the website.

 

Specifically speaking:

 First, check my webpage code.

<Script type = "text/javascript"> $ (function () {var url = "ws: // xxxx: xx" + "@ Url. action ("RequestProcessCenter") "; var ws; function connect () {ws = new WebSocket (url); $ (" # TopicContent "). append ("Connecting \ n"); ws. onopen = function () {$ ("# TopicContent "). append ("connected \ n") ;}; ws. onmessage = function (evt) {console. log (evt. data); $ ("# TopicContent "). append (evt. data) ;}; ws. onclose = function () {$ ("# TopicContent "). append ("disabled \ 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 ("Connection closed") ;}}; $ ("# open "). click (function () {connect () ;}); $ ("# close "). click (function () {ws. close () ;}); </script>
 

Background code:

 
Public void RequestProcessCenter () {if (HttpContext. isWebSocketRequest) {var currUser = GetCurrUser (); this. _ UserName = currUser. loginName; HttpContext. acceptWebSocketRequest (ProcessTopic);} else {HttpContext. response. write ("request failed ");}}
 

The url format required by webSocket should be correct.

 

Error display

200 is returned. Although the request is successful, the result is not what we want.

 

The request method is indeed websocket, but the error exists. Why? I have searched a lot of materials, but I have not found any solution to this problem. Maybe I am looking for a problem, but I have read the first three pages of Baidu and have no solutions. I did a test on my own and found that the test was effective.

The website I deployed on the server uses the default port 80, and the access will fail. What if webSocket does not need to be bound to the same port of the website?

After this test:

1. Bind the local port 80 to the domain name webSocket to use the domain name. Port 80 is invalid.
2. Bind the local port 80 to the domain name webSocket. Use the host address of port 2017 to use the Server IP address.
3. The local port 2017 is not bound to the domain name webSocket. Port 80 is invalid.
4. The local port 2017 is not bound to the domain name webSocket. The port 2017 is valid.

Summary port 80 may be subject to System Restrictions
On the other hand, will domain name binding affect the absence of tests?

 

The websocket service is not available even if the Internet returns 200.

In this case, you need to add two websites to the IIS server, one for normal port 80 webpage access and the other for separate WebSocket functions, these two websites can use the same program version. I am doing this and there is no good idea, cainiao-level figures.

 

Https://www.infoq.com/articles/Web-Sockets-Proxy-Servers

This website introduces some knowledge about WebSocket and websocket uses port 80-433 by default. Maybe I am wondering if the port bound to my website is the same as that bound to websocket, the Internet request is an error at this time. This problem cannot be further investigated at half past one, and the temporary function is achieved. However, this solution is not very good, but it can only be said to meet the requirements, however, the requirement process cannot be simplified.

 

Leave a conjecture that it is feasible for me to access the server. Port 80 is used, and the websocket service can be used normally, direct access is my local service, so the firewall will not block, but when I use the Internet to access, the inbound rules may block my requests, click the connection, and initiate a WebSocket call, the Service port also uses port 80, which causes firewall identification problems.

 

I guess it is unreasonable, but I still have to solve the problem by analyzing the cause of the problem.

 

 , I hope I can come back and see my step when my technology is successful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.