FPGA_WebLab/server/udpServer.ts

36 lines
635 B
TypeScript

import _ from "lodash"
import { type udp } from "bun"
declare var self: Worker
export type UDPServerMsgType = "port"
interface BinaryTypeList {
arraybuffer: ArrayBuffer;
buffer: Buffer;
uint8array: Uint8Array;
// TODO: DataView
// dataview: DataView;
}
type BinaryType = keyof BinaryTypeList;
const udpServer = await Bun.udpSocket({
port: 33000,
socket: {
data(
_socket: udp.Socket<BinaryType>,
data: BinaryTypeList[BinaryType],
port: number,
address: string,
) {
// todo : Handle Recieved Data
}
}
})
export function udpServerPort(): number {
return udpServer.port
}