34 lines
700 B
TypeScript
34 lines
700 B
TypeScript
import { parentPort } from "worker_threads"
|
|
import { MsgProtocol } from "./msgProtocol"
|
|
import _ from "lodash"
|
|
|
|
declare var self: Worker
|
|
export type UDPServerMsgType = "port"
|
|
|
|
const udpServer = await Bun.udpSocket({
|
|
port: 33000,
|
|
socket: {
|
|
data(_socket, _buf, _port, _addr) {
|
|
// todo : Handle Recieved Data
|
|
}
|
|
}
|
|
})
|
|
|
|
parentPort?.on("message", (msg: MsgProtocol.MessageQuery) => {
|
|
if (MsgProtocol.isMessageQuery(msg)) {
|
|
switch (msg.command) {
|
|
case "port": {
|
|
postMessage(MsgProtocol.genMessageResult(udpServer.port, msg))
|
|
break
|
|
}
|
|
default: {
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
})
|
|
|
|
postMessage("UDP Server Start Successfully!")
|