socket.TCPSocketConnection on('message')有概率无法响应

socket.TCPSocketConnection on('message')有概率无法响应

HarmonyOS
2024-05-10 18:10:39
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
youganlan
serverSocket.on(“connect”, (clientSocket: socket.TCPSocketConnection) => { 
  console.log(waitForRequest connect ${clientSocket.clientId}); // 1 
clientSocket.on(“message”, (data) => { // MessageCallBackBean 
  this.onMessage(clientSocket, data); // 2 
}); 
clientSocket.on(“error”, (err: Error) => { 
  console.log(waitForRequest-clientSocket-error,name=${err.name},msg=${err.message},stackTrace=${err.stack}); 
// closeSocket(clientSocket, false) 
}) 
clientSocket.on(“close”, () => { 
console.log(“waitForRequest-clientSocket-connection-close”); 
// closeSocket(clientSocket, true) 
}) 
console.log(waitForRequest connect2 ${clientSocket.clientId}); 
})

这个方法偶现无法正常响应message方法,也就是// 1处能正常打印日志,// 2处日志无法正常打印,导致无法请求数据无法传输;

2. httpRequest.request方法无法返回正常值,均收到timeout的exceptionawait httpRequest.requestInStream(url, option)

两个问题:

1. connection.destroy(); 不能写在finally里面,要写在then和catch里面

2. onMessage方法里面,data格式不正确,使用类似这种是可以的。 const data = “HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello, World!”;

修改之后运行成功的日志

02-01 14:13:53.244 22598-22985 C015b0/NetMgrSubsystem com.examp…lication I NETSTACK [socket_exec.cpp 1742] manager is ready with registering message event 
02-01 14:13:53.244 22598-22598 A03d00/JSAPP com.examp…lication I waitForRequest connect2 2 
02-01 14:13:53.244 22598-22985 C015b0/NetMgrSubsystem com.examp…lication I NETSTACK [socket_exec.cpp 1780] ClientRecv: fd is 70, buf is GET /ping HTTP/1.1 
02-01 14:13:53.246 22598-22598 A03d00/JSAPP com.examp…lication I waitForRequest-clientSocket-message,remoteInfo={“message”:{},“remoteInfo”:{“address”:“127.0.0.1”,“family”:“IPv4”,“port”:47086,“size”:121}} 
02-01 14:13:53.246 22598-22827 C015b0/NetMgrSubsystem com.examp…lication I NETSTACK [http_response.cpp 49] HEAD: HTTP/1.1 200 OK 
02-01 14:13:53.247 22598-22985 C015b0/NetMgrSubsystem com.examp…lication I NETSTACK [socket_exec.cpp 1780] ClientRecv: fd is 70, buf is , size is 0 bytes
分享
微博
QQ
微信
回复
2024-05-11 09:49:19
相关问题
Socket概率收不到message
1993浏览 • 1回复 待解决
HarmonyOS Tab组件无法响应onPageShow
307浏览 • 1回复 待解决
ohos.net.socket (Socket连接)链接不上
5423浏览 • 1回复 待解决
概率性报错5400104、5400103怎么处理
580浏览 • 1回复 待解决
native创建socket会失败
1702浏览 • 1回复 待解决
冷启动报错Error message
1981浏览 • 1回复 待解决
socket连接NetAddress获取问题
320浏览 • 1回复 待解决
app启动crash报错Error message:MainPage:
1677浏览 • 1回复 待解决
HarmonyOS 经典蓝牙的socket通信问题
260浏览 • 1回复 待解决
Socket接口库可以绑定域名吗
447浏览 • 1回复 待解决