Bun.udpSocket function | API Reference | Bun
BuildDocsReferenceGuidesBlogDiscord/
Bun/
udpSocketFudpSocket
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
Bun/
udpSocketFudpSocket
function
udpSocketfunction
udpSocketDataBinaryType extends keyof
BinaryTypeList = 'buffer'>(options:
SocketOptionsDataBinaryType>): Promise
SocketDataBinaryType>>;
Create a UDP socket
@param options
The options to use when creating the server
function
udpSocketDataBinaryType extends keyof
BinaryTypeList = 'buffer'>(options:
ConnectSocketOptionsDataBinaryType>): Promise
ConnectedSocketDataBinaryType>>;
Create a UDP socket
@param options
The options to use when creating the server
Referenced typesinterface
SocketOptionsDataBinaryType extends
BinaryType>
binaryType?: DataBinaryType
hostname?: string
port?: number
socket?:
SocketHandlerDataBinaryType>interface
SocketDataBinaryType extends
BinaryType>readonly
address:
SocketAddressreadonly
binaryType: keyof
BinaryTypeListreadonly
closed: booleanreadonly
hostname: stringreadonly
port: number
addMembership(multicastAddress: string,interfaceAddress?: string): boolean;
Join a multicast group.
@param multicastAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
addSourceSpecificMembership(sourceAddress: string,groupAddress: string,interfaceAddress?: string): boolean;
Join a source-specific multicast group.
@param sourceAddress
The source address
@param groupAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
close(): void;
dropMembership(multicastAddress: string,interfaceAddress?: string): boolean;
Leave a multicast group.
@param multicastAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
dropSourceSpecificMembership(sourceAddress: string,groupAddress: string,interfaceAddress?: string): boolean;
Leave a source-specific multicast group.
@param sourceAddress
The source address
@param groupAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
ref(): void;
reload(handler:
SocketHandlerDataBinaryType>): void;
send(data:
Data,port: number,address: string): boolean;
sendMany(packets: readonly number |
Data[]): number;
setBroadcast(enabled: boolean): boolean;
Enable or disable SO_BROADCAST socket option.
@param enabled
Whether to enable broadcast
@returns
The enabled value
setMulticastInterface(interfaceAddress: string): boolean;
Set the IP_MULTICAST_IF socket option to specify the outgoing interface for multicast packets.
@param interfaceAddress
The address of the interface to use
@returns
true on success
setMulticastLoopback(enabled: boolean): boolean;
Enable or disable IP_MULTICAST_LOOP socket option.
@param enabled
Whether to enable multicast loopback
@returns
The enabled value
setMulticastTTL(ttl: number): number;
Set the IP_MULTICAST_TTL socket option.
@param ttl
Time to live value for multicast packets
@returns
The TTL value
setTTL(ttl: number): number;
Set the IP_TTL socket option.
@param ttl
Time to live value
@returns
The TTL value
unref(): void;interface
ConnectSocketOptionsDataBinaryType extends
BinaryType>
binaryType?: DataBinaryType
connect: { hostname: string; port: number }
hostname?: string
port?: number
socket?:
ConnectedSocketHandlerDataBinaryType>interface
ConnectedSocketDataBinaryType extends
BinaryType>readonly
address:
SocketAddressreadonly
binaryType: keyof
BinaryTypeListreadonly
closed: booleanreadonly
hostname: stringreadonly
port: numberreadonly
remoteAddress:
SocketAddressaddMembership(multicastAddress: string,interfaceAddress?: string): boolean;
Join a multicast group.
@param multicastAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
addSourceSpecificMembership(sourceAddress: string,groupAddress: string,interfaceAddress?: string): boolean;
Join a source-specific multicast group.
@param sourceAddress
The source address
@param groupAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
close(): void;
dropMembership(multicastAddress: string,interfaceAddress?: string): boolean;
Leave a multicast group.
@param multicastAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
dropSourceSpecificMembership(sourceAddress: string,groupAddress: string,interfaceAddress?: string): boolean;
Leave a source-specific multicast group.
@param sourceAddress
The source address
@param groupAddress
The multicast group address
@param interfaceAddress
Optional interface address to use
@returns
true on success
ref(): void;
reload(handler:
ConnectedSocketHandlerDataBinaryType>): void;
send(data:
Data): boolean;
sendMany(packets: readonly
Data[]): number;
setBroadcast(enabled: boolean): boolean;
Enable or disable SO_BROADCAST socket option.
@param enabled
Whether to enable broadcast
@returns
The enabled value
setMulticastInterface(interfaceAddress: string): boolean;
Set the IP_MULTICAST_IF socket option to specify the outgoing interface for multicast packets.
@param interfaceAddress
The address of the interface to use
@returns
true on success
setMulticastLoopback(enabled: boolean): boolean;
Enable or disable IP_MULTICAST_LOOP socket option.
@param enabled
Whether to enable multicast loopback
@returns
The enabled value
setMulticastTTL(ttl: number): number;
Set the IP_MULTICAST_TTL socket option.
@param ttl
Time to live value for multicast packets
@returns
The TTL value
setTTL(ttl: number): number;
Set the IP_TTL socket option.
@param ttl
Time to live value
@returns
The TTL value
unref(): void;
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →