Skip to content

Commit

Permalink
feat(logging): add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
syroegkin committed May 22, 2023
1 parent 1fb9bd8 commit b15a417
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"keywords": [
"zx-spectrum",
"nxtp",
"timeserver"
"timeserver",
"zx-spectrum next"
],
"author": "",
"license": "GPL-3.0-or-later",
Expand Down
10 changes: 8 additions & 2 deletions src/nxtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ function sockerWritePromise(
}

export function nxtp(socket: net.Socket) {
console.log(`Client connected from ${socket.remoteAddress}`);
// @todo: Add the time when it gets connected, remoted IP address and the timezone requested
// I really keen to have some statistics on the server
const { remoteAddress } = socket;
console.log(`${remoteAddress}: new lient connected`);

socket.on('data', async (data: Buffer) => {
try {
// Process request
const nxtpTimezone = processRequest(data);
console.log(`${remoteAddress}: Requesting time for ${nxtpTimezone}`);
// Convert timezone to IANA
const iana = nxtpToIana(nxtpTimezone);
console.log(`${remoteAddress}: transformed to ${iana}`);
// Generate response
const response = generateResponse(iana);
// Send response
await sockerWritePromise(socket, response);
// Close socket
socket.destroy();
console.log(`${remoteAddress}: close connection`);
} catch (e: unknown) {
console.log(e);
console.log(`${remoteAddress}: ${(e as Error).message}`);
socket.destroy();
}
});
Expand Down

0 comments on commit b15a417

Please sign in to comment.