InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
展开阅读全文

今天使用node.js,发现在链接成功后,在使用ws.send()出现以下错误:

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

解决方法:

把ws.send()写到ws.onopen事件里,就可以了