# UDP
官方文档:
中文翻译:
## Server
应用场景: 心跳服务。
```js
import dgram from 'dgram';
const server = dgram.createSocket('udp4');
server.on('error', (err) => {
// 处理错误
server.close();
server.bind(6666);
});
server.on('message', async(msg, info) => {
// 处理消息
});
server.on('listening', () => {
const address = server.address();
console.log('Push Client Server listening at %s - %s', `${address.address}:${address.port}`, new Date());
});
server.bind(6666);
```