We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
自定义样例onOnline onOffline没有正确运行
The text was updated successfully, but these errors were encountered:
`import { echo } from 'coa-echo' import { _ } from 'coa-helper' import { createServer, Server, Socket } from 'net' import { CoaClient } from './CoaClient' import { CoaClientPool } from './CoaClientPool'
export class CoaApplication { private readonly listenPort: number private readonly clientPool: CoaClientPool private readonly tcpServer: Server
constructor(clientPool: CoaClientPool, listenPort: number) { this.clientPool = clientPool this.listenPort = listenPort this.tcpServer = createServer((socket) => this.connectionListener(socket)) }
// 监听 start() { this.tcpServer.listen(this.listenPort, () => { echo.cyan('[TCP] Listening on port ' + this.listenPort) }) }
// 监听连接事件 private connectionListener(socket: Socket) { let client: T // 只有首次收到数据,才开始初始化一个客户端
socket.on('data', async (raw) => { if (client == undefined) { client = await this.clientPool.connect(socket); await client.onOnline(client!.clientId); } await client.onData(raw); }) // 关闭连接的时候销毁数据 socket.on('close', async () => { if (client) await this.clientPool.close(client) await client.onOffline(client.clientId); }) socket.on('error', _.noop) // 如果超过300秒没有任何响应,则断开连接 socket.on('timeout', () => socket.end(() => socket.destroy())) socket.setTimeout(300 * 1000)
} } `
这样似乎就成功修复了问题
Sorry, something went wrong.
No branches or pull requests
自定义样例onOnline onOffline没有正确运行
The text was updated successfully, but these errors were encountered: