Skip to content

Commit 8ad166a

Browse files
Update Server.ts
1 parent 99f5e13 commit 8ad166a

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import dgram from "dgram";
2-
const port: number = 8080;
3-
42
import express, { Application, Request, Response } from "express";
3+
54
const app: Application = express();
5+
const port: number = 8080;
6+
7+
/** HTTP Server for checking status */
68
app.get('/', (req: Request, res: Response) => {``
79
res.send({ message: 'Server is active', timestamp: new Date() });
810
});
911

1012
const Server = dgram.createSocket('udp4');
1113

12-
/** Broker listen to all subscribers and manage protocol */
13-
1414
Server.on('error', (err) => {
1515
console.log(`Server error:\n${err.stack}`);
1616
Server.close();
1717
});
1818

19+
/** Receive Messages */
1920
Server.on('message', (msg, rinfo) => {
2021
console.log(`Server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
2122

@@ -30,13 +31,11 @@ Server.on('message', (msg, rinfo) => {
3031

3132
/** Launch server and listen on given port */
3233
try {
33-
3434
Server.on('listening', () => {
3535
const address = Server.address();
3636
console.log(`Server listening ${address.address}:${address.port}`);
3737
});
3838

39-
4039
Server.bind(port, (): void => {
4140
console.log(`UDP Datagram Server is active at http://localhost:${port}`);
4241
});

0 commit comments

Comments
 (0)