websocket html5,html - Connecting to HTML5 Websocket - Stack Overflow

博客探讨了HTML5 WebSocket连接中不同教程中出现的端口差异。作者疑惑为何端口会有所不同,以及如何确定正确的连接端口。在尝试自定义连接时遇到了'Unexpected response code: 200'的错误。问题集中在WebSocket连接的建立、端口选择及其对应用动态性的影响上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm a bit confused about HTML5 Websockets. I've looked at numerous tutorials out there and a lot of them have different variations of connecting using different ports. What do these ports mean?

Adobe for instance, uses this:

new WebSocket('ws://localhost:1740');

Then another tutorial has this where no ports are required:

new WebSocket("ws://www.websockets.org");

And finally a third tutorial has a port, but it's completely different:

new WebSocket("ws://localhost:8080/echo");

My question would be, why do these vary? How do I know which ports to connect to? Also, I've attempted to do my own connection:

var ws = new WebSocket("ws://test.ontarget-network.com/");

But I get the following error: Unexpected response code: 200

I've tested around and tried connecting to various other "ports" (not knowing what I'm doing obviously, typing in random numbers) and this error would disappear, however, my code

ws.onopen = function(){

alert("Connection Established");

};

would not execute.

I'm trying to fully understand HTML5's Websockets API so I can experiment and create more dynamic applications. Thanks for the help.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值