Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

javascript - websocket 301 using domain but not using ip direcly

I run a simple websocket using

const WebSocket = require('ws')

const wss = new WebSocket.Server({ port: 8080 });

when I try to connect to the server using

const connection = new WebSocket('ws://84.***.***.***:8080') // my ip adress

everything works fine, no error, the connection event gets triggered and I can send a message.
If I use my domain though, i.e.

const connection = new WebSocket('ws://sub.example.com:8080')

I get this error:

WebSocket connection to 'ws://sub.example.com:8080/' failed: Error during WebSocket handshake: Unexpected response code: 301

I am using an A record to point the subdomain to my actual domain (using cloudflair, imported from namecheap). Wikipedia tells me

The HTTP response status code 301 Moved Permanently is used for permanent redirecting, meaning current links or records using the URL this response is received for should be updated.

Any Ideas on what I am doing wrong?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...