
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Plain UDP Socket and Client
npm i --save socket-udp
//app.js
import { UDPClient } from 'socket-udp'
const client = new UDPClient({ port: 44002 })
client.write(Buffer.from('Hello, World!', 'utf8'))
//server.js
import { UDPSocket } from 'socket-udp'
const socket = new UDPSocket({ port: 44002 })
for await (const message of socket) {
console.log(message.toString('utf8'))
}
After just start the server node server.js
and start your app node app.js
. That's all, you've just sent and received message.
UDPClient
Extends Writabable
Stream
Extends WritableOptions and dgram.SocketOptions
options
<object>
– optional
type
<'udp4' | 'udp6'>
– optional. Default 'udp4'
port
<string | number>
– optional. Target port. Default 44002
address
<string>
– optional. Target address. Default '127.0.0.1'
or '::1'
bindAddress
<dgram.BindOptions>
– optional.
port
<integer>
— optional.address
<string>
— optional.exclusive
<boolean>
— optional.fd
<integer>
— optional.origin
: <dgram.Socket>
port
: <number>
address
: <string>
family
: <string>
allowWrite
: <boolean>
targetPort
: <number>
targetAddress
: <number>
'ready'
Emitted when the client "establishes" udp connection.
import { UDPClient } from 'socket-udp'
const client = new UDPClient({ port: 44002 })
client.write(Buffer.from('hi!', 'utf8'))
UDPSocket
Extends Readable
Stream
It is a UDP socket in readable stream
form.
Extends ReadableOptions and dgram.SocketOptions
options
<object>
– required
type
<'udp4' | 'udp6'>
– optional. Default 'udp4'
port
<string | number>
– optional. Default 44002
address
<string>
– optional. Default '127.0.0.1'
or '::1'
pushMeta
<boolean>
– optional. Will push not a raw message, but an object with remoteInfo. Message data will be placed in field body
. Default false
origin
: <dgram.Socket>
port
: <number>
address
: <string>
family
: <string>
allowPush
: <boolean>
All Readable
events of course and:
'ready'
Emitted when socket started and ready to receive data.
'data'
Emitted right after a message was received
message
<Buffer>
handleMessage
(body: Buffer, head: MessageHead) => void
– handles raw messages from dgram.Socket.
If you need to handle data before any manipulation then overwrite it.import fs from 'node:fs'
import { UDPSocket } from 'socket-udp'
const socket = new UDPSocket()
const writer = fs.createWriteStream('/some/path')
socket.pipe(writer)
import { UDPSocket } from 'socket-udp'
const socket = new UDPSocket({ port: 44002, pushMeta: true })
for await (const { address, port, body } of socket) {
console.log(`From ${address}:${port} you recieved`, JSON.parse(body.toString('utf8')))
}
DEFAULT_PORT
<number>
: 44002
License (MIT)
FAQs
Basic UDP Socket and Client
We found that socket-udp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.