Skip to content

Commit

Permalink
Merge pull request #74 from Protonull/fix-end-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Huskydog9988 authored Aug 14, 2023
2 parents a302849 + 242ea10 commit 17c5cd2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class TcpServer {
this.server = net.createServer({}, (socket) => {
const client = new TcpClient(socket, this, handler)
this.clients[client.id] = client
socket.on('end', () => delete this.clients[client.id])
socket.on('close', () => delete this.clients[client.id])
})

Expand Down Expand Up @@ -141,11 +140,16 @@ export class TcpClient {
})

socket.on('end', () => {
this.log('Ended')
// This event is called when the other end signals the end of transmission, meaning this client is
// still writeable, but no longer readable. In this situation we just want to close the socket.
// https://nodejs.org/dist/latest-v18.x/docs/api/net.html#event-end
this.kick('Ended')
})

socket.on('timeout', () => {
this.warn('Timeout')
// As per the docs, the socket needs to be manually closed.
// https://nodejs.org/dist/latest-v18.x/docs/api/net.html#event-timeout
this.kick('Timed out')
})

socket.on('error', (err: Error) => {
Expand Down

0 comments on commit 17c5cd2

Please sign in to comment.