JSON.stringify( new WebSocket("ws://localhost:8080/websocket.do"))

本文介绍了一个简单的JavaScript示例,展示了如何使用WebSocket进行实时通信,并利用LocalStorage来存储对象数据。包括创建WebSocket连接、设置对象属性及将对象转换为JSON字符串存入浏览器本地存储的过程。
//存在session
                    //先是 test 后是 ws
                    var test = {test: '', test1: 1,fun:function () {
                        console.info("函数可以吗")
                    }};
                    console.info("test的类型"+typeof test)
                    var webSocket = new WebSocket("ws://localhost:8080/websocket.do");
                    webSocket.niMei="你妹";
                    console.info("webSocket的类型"+typeof webSocket);
                    console.info("验证websocket不是空的"+webSocket.url)

                    localStorage.setItem("test", JSON.stringify(test))
                    console.info("取test"+localStorage.getItem("test"))

                    localStorage.setItem("webSocket", JSON.stringify(webSocket))
                    console.info("取webSocket"+localStorage.getItem("webSocket"))

这里写图片描述

这里写图片描述

Error in event handler: TypeError: Cannot read properties of undefined (reading 'find') at UNe.checkSearchSummary (chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:123:12964) at U$ (chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:65:6240) at UNe.checkSearchSummary (chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:65:6057) at chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:123:9837 at U$ (chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:65:6240) at Le (chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:65:20785) at chrome-extension://apiogbndjcdfccgecgbaljjlhdjpkbho/content-ui/index.iife.js:123:9792 index.html:492 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:492 index.html:521 🚨 WebSocket 错误: Event ws.onerror @ index.html:521 index.html:492 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:492 index.html:521 🚨 WebSocket 错误: Event ws.onerror @ index.html:521 index.html:492 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:492 index.html:521 🚨 WebSocket 错误: Event ws.onerror @ index.html:521 index.html:492 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:492 index.html:521 🚨 WebSocket 错误: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} ws.onerror @ index.html:521 error connectWebSocket @ index.html:521 index.html:492 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:492 index.html:521 🚨 WebSocket 错误: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} ws.onerror @ index.html:521 error connectWebSocket @ index.html:521 setTimeout ws.onclose @ index.html:520
最新发布
12-02
正在检查服务器状态: http://localhost:8080/api/health webSocketService.ts:155 GET http://localhost:8080/api/health net::ERR_ABORTED 401 (Unauthorized) checkServerStatus @ webSocketService.ts:155 connect @ webSocketService.ts:223 (匿名) @ main.ts:75 webSocketService.ts:169 服务器状态检查: 认证失败,但仍允许尝试WebSocket连接 webSocketService.ts:90 没有可用的refreshToken用于刷新 webSocketService.ts:248 尝试连接WebSocket: ws://localhost:8080/websocket/realtime (时间: 2025-08-26T01:36:08.129Z) webSocketService.ts:155 提取 加载失败:GET "http://localhost:8080/api/health". checkServerStatus @ webSocketService.ts:155 connect @ webSocketService.ts:223 (匿名) @ main.ts:75 webSocketService.ts:253 WebSocket connection to 'ws://localhost:8080/websocket/realtime' failed: (匿名) @ webSocketService.ts:253 webSocketService.ts:304 WebSocket错误 (连接尝试: 1/10): 类型: error, 目标: [object WebSocket] socket.onerror @ webSocketService.ts:304 webSocketService.ts:324 WebSocket连接关闭 (连接尝试: 0/10): 代码: 1006, 原因: 无原因, 是主动关闭: false webSocketService.ts:489 尝试重新连接WebSocket (1/10)... 等待 2000ms webSocketService.ts:136 正在检查服务器状态: http://localhost:8080/api/health webSocketService.ts:155 GET http://localhost:8080/api/health net::ERR_ABORTED 401 (Unauthorized) checkServerStatus @ webSocketService.ts:155 connect @ webSocketService.ts:223 (匿名) @ webSocketService.ts:494 setTimeout reconnect @ webSocketService.ts:493 socket.onclose @ webSocketService.ts:337 webSocketService.ts:155 提取 加载失败:GET "http://localhost:8080/api/health". checkServerStatus @ webSocketService.ts:155 connect @ webSocketService.ts:223 (匿名) @ webSocketService.ts:494 setTimeout reconnect @ webSocketService.ts:493 socket.onclose @ webSocketService.ts:337 webSocketService.ts:169 服务器状态检查: 认证失败,但仍允许尝试WebSocket连接 webSocketService.ts:90 没有可用的refreshToken用于刷新 webSocketService.ts:248 尝试连接WebSocket: ws://localhost:8080/websocket/realtime (时间: 2025-08-26T01:36:10.186Z) webSocketService.ts:253 WebSocket connection to 'ws://localhost:8080/websocket/realtime' failed: (匿名) @ webSocketService.ts:253 webSocketS
08-27
index.html:480 ⚠️ 连接断开,5秒后重连... (anonymous) @ index.html:480 index.html:459 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:459 index.html:485 WebSocket 错误: Event (anonymous) @ index.html:485 index.html:480 ⚠️ 连接断开,5秒后重连... (anonymous) @ index.html:480 index.html:459 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:459 index.html:485 WebSocket 错误: Event (anonymous) @ index.html:485 index.html:480 ⚠️ 连接断开,5秒后重连... (anonymous) @ index.html:480 index.html:459 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:459 index.html:485 WebSocket 错误: Event (anonymous) @ index.html:485 index.html:480 ⚠️ 连接断开,5秒后重连... (anonymous) @ index.html:480 index.html:459 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:459 index.html:485 WebSocket 错误: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} (anonymous) @ index.html:485 index.html:480 ⚠️ 连接断开,5秒后重连... (anonymous) @ index.html:480 index.html:459 WebSocket connection to 'ws://localhost:8080/' failed: connectWebSocket @ index.html:459 index.html:485 WebSocket 错误: Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} (anonymous) @ index.html:485 error connectWebSocket @ index.html:484 setTimeout (anonymous) @ index.html:481 index.html:480 ⚠️ 连接断开,5秒后重连...
11-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值