-
-
Couldn't load subscription status.
- Fork 33.6k
Closed
Labels
questionIssues that look for answers.Issues that look for answers.wrong repoIssues that should be opened in another repository.Issues that should be opened in another repository.
Description
- Version:
- Platform:
- Subsystem:
- Version: v8.9.3
- Platform: win10 64bit
Why net create a IPC server, the coming socket without pid info. Under this condition I can't define which socket it is.Then I must send a message to tell server it's pid info. Code beblow here
const clientList: IClient[] = []
enum MSG_TYPE {
INIT,
DATA,
COMMUNICATE
}
interface IClient {
id: number | string
socket: net.Socket
}
const handleClientMsg = (msg, current) => {
switch (msg.type) {
case MSG_TYPE.INIT:
let client = clientList.find(item => item.socket === current)
if (client) {
client.id = msg.id
}
break
case MSG_TYPE.COMMUNICATE: {
let client = clientList.find(item => item.id === msg.id)
if (client) {
client.socket.write(msg.data)
}
}
break
default:
break
}
}
server.on('connection', socket => {
clientList.push({ id: undefined, socket })
socket.on('data', function (msg) {
let message = JSON.parse(msg.toString())
handleClientMsg(message, this)
console.log(this, this === socket)
log(chalk.green(clientList.map(item => item.id).toString()))
})
})If soeckt has pid info, I can store it's pid info during connection event
Metadata
Metadata
Assignees
Labels
questionIssues that look for answers.Issues that look for answers.wrong repoIssues that should be opened in another repository.Issues that should be opened in another repository.