Orange_air 2021-07-25 11:59 采纳率: 100%
浏览 463
已结题

求websocket中nodejs已经显示连接上,但是readystate还是0,急

 //声明连接,房间号,名称
    ws
    roomCount = 100
    name
    IP='ws://127.0.0.1:8888'

    // websocket建立连接
    link(){
        //建立连接
        this.ws = new WebSocket(this.IP)
        //连接成立触发
        this.ws.onopen = this.onopen()
}
        
onopen(){
        console.log('success connected')
        var randomScore = parseInt(Math.random()*3)
        console.log('parseInt(Math.random()*5)=============>'+randomScore)
        console.log(this.ws.readyState)
        while(true){
            if(this.ws.readyState==1){
                this.ws.send({type:0,score:randomScore})
                break
            }
        }
}

```}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月2日
    • 创建了问题 7月25日