1.2K Star 6.4K Fork 5.4K

OpenHarmony / docs

 / 详情

[问题咨询]: webSocket

待办的
创建于  
2024-03-25 22:22

问题描述

我写了一个page,代码如下,在点击按钮后链接websocket服务。但不成功,给出的Log是:
app Log: The webSocket.createWebSocket interface in the Previewer is a mocked implementation
and may behave differently than on a real device.
app Log: The WebSocket.connect interface in the Previewer is a mocked implementation and may
behave differently than on a real device.
app Log: Connection failed. Err:{"code":"","data":"","name":"","message":"","stack":""}

//////code/////////////
import webSocket from '@ohos.net.webSocket';
import { BusinessError } from '@ohos.base';

@entry
@citizenl
struct Second {
@后蜗牛 message: string = 'Hi Linke09';

build() {
Row() {
Column() {
Text(this.message)
.fontColor('red')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button(){
Text('Back')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Normal)
.margin({top:20})
.backgroundColor('#0DBFBB')
.width('40%')
.height('5%')
.onClick(()=> {
console.info("Succeeded in clicking the 'Next' button.");
let defaultIpAddress = "ws://localhost:2333";
let ws = webSocket.createWebSocket();

      ws.connect(defaultIpAddress, (err: BusinessError, value: boolean) => {
        if (!err) {
          console.log("Connected successfully");
        } else {
          console.log("Connection failed. Err:" + JSON.stringify(err));
        }
      });
    })
  }
  .width('100%')
}
.height('100%')

}
}

评论 (1)

qichao77 创建了任务
qichao77 添加了
 
question
标签
展开全部操作日志

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 @NEEN @zengyawen @时睿 @Peter_1988 。如果需要调整订阅PR、Issue的变更状态,请访问链接

Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer @NEEN @zengyawen @时睿 @Peter_1988 for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

openharmony_ci 添加了
 
waiting_for_assign
标签

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
7387629 openharmony ci 1656582662
其他
1
https://gitee.com/openharmony/docs.git
git@gitee.com:openharmony/docs.git
openharmony
docs
docs

搜索帮助

344bd9b3 5694891 D2dac590 5694891