Udp server

Author: g | 2025-04-24

★★★★☆ (4.1 / 1765 reviews)

sub lab

Download Udp Server; Udp Client Server; Udp Socket Server; Boost Udp Server; Udp Udp Download; Udp Download Test; Udp Software Download; Download Udp Server Software.

visio 2019 download

Linux UDP (udp server linux)

F1-22 Updated May 22, 2023 TypeScript luka2220 / dns-resolver-api Star 1 Code Issues Pull requests A simple API that can resolve the IP address for a host nodejs dns network-programming udp-client rfc1035 Updated Dec 24, 2024 TypeScript paranlee / deno-tcp-udp Star 1 Code Issues Pull requests Use Deno as TCP/UDP server. typescript tcp daemon udp tcp-server tcp-client udp-server udp-client deno Updated Aug 17, 2021 TypeScript ablomer / satisfactory-server-status Star 0 Code Issues Pull requests 🎮 A real-time server status monitor for Satisfactory dedicated servers that leverages UDP polling and WebSocket connections for efficient state tracking. docker dashboard websocket udp socket-io node-js udp-client satisfactory Updated Jan 18, 2025 TypeScript Improve this page Add a description, image, and links to the udp-client topic page so that developers can more easily learn about it. Curate this topic Add this topic to your repo To associate your repository with the udp-client topic, visit your repo's landing page and select "manage topics." Learn more I am often asked to measure the bandwidth of a network path. Many users test this using a simple HTTP download or with speedtest.net. Unfortunately, any test using TCP will produce inaccurate results, due to the limitations of a session-oriented protocol. TCP window size, latency, and the bandwidth of the return channel (for ACK messages) all affect the results. The most reliable way to measure true bandwidth is with UDP. That’s where my friends iperf and bwm-ng come in handy.iperf is a tool for measuring bandwidth and reporting on throughput, jitter, and data loss. Others have written handy tutorials, but I’ll summarise the basics here.iperf will run on any Linux or Unix (including Mac OSX), and must be installed on both hosts. Additionally, the “server” (receiving) host must allow incoming traffic to some port (which defaults to 5001/UDP and 5001/TCP). If you want to run bidirectional tests with UDP, this means you must open 5001/UDP on both hosts’ firewalls.iptables -I INPUT -p udp -m udp --dport 5001 -j ACCEPTA network path is really two paths – the downstream path and the upstream (or return) path. With iperf, the “client” is the transmitter and the “server” is the receiver. So we’ll use the term “downstream” to refer to traffic transmitted from the client to the server, and “upstream” to refer to the opposite. Since these two paths can have different bandwidths and entirely different routes, we should measure them separately.Start by opening terminal windows to both the client and server hosts, as well as the iperf man page. On the server, you only have to start listening. This runs iperf as a server on the default 5001/UDP.root@server:~# iperf -s -u------------------------------------------------------------Server listening on UDP port 5001Receiving 1470 byte datagramsUDP buffer size: 124 KByte (default)------------------------------------------------------------The server will output test results, as well as report them back to the client for display.On the client, you have many options. You can push X data (-b) for Y seconds (-t). For example, to push 1 mbit for 10 seconds:root@client:~# iperf -u -c server.example.com -b 1M -t 10------------------------------------------------------------Client connecting to 172.16.0.2, UDP port 5001Sending 1470 byte datagramsUDP

Create UDP CUSTOM and UDP REQUEST Servers - Custom UDP

UDP Hole-PunchingPurposeHave a server negotiate a peer-to-peer connection between two clients in the most direct way possible.Demonstrate Hole-Punching / NAT traversal using the UDP protocol.Demonstrate the support of UPnP.MethodServer:Uses TCP to manage available clients.Uses UDP to learn the public End Point (IP and Port) of clients.Publishes list of connected clients and their End Points.Relays connection requests between clients.Client:Attempts to use UPnP to forward a port to itself on the router (Optional).Sends the server the following information:Hostname (as a friendly name)Whether UPnP is enabled or not.Local UDP port that the client is listening on.List of local IP addresses.Sends a message to the server that it wishes to connect to another client / Receives a message from the server that another client wishes to connect to it. (Both clients will attempt to connect to each other at the same time)Sends 3 ACK requests to each local IP of other client to determine if clients are on the same LAN.If there was no response, sends 99 ACK requests to public/external End Point.If UDP Hole-Punching is successful, a chat window will be shown and a conversation can begin.Everything the client attempts is outputted to a textbox for review.InstructionsRun the GetConnected server executable on a publicly reachable server. (Forward TCP and UDP port to your server on your router.)Change value 'ServerEndpoint' in Client.cs to your servers public IP.Run the P2PClient executable on PCs you want to connect.Click the 'Connect' button in the top left to connect to the server. The server will ensure you always have an updated list of available clients.Select a client and click 'Connect' in the bottom right to connect to it.Observe as two clients begin to establish a connect to each other.. Download Udp Server; Udp Client Server; Udp Socket Server; Boost Udp Server; Udp Udp Download; Udp Download Test; Udp Software Download; Download Udp Server Software. Voltssh-X - UDP Management Script ssh script panel udp vps vpn-server udp-server dropbear udp-client ssh-manager udp-client-server udp-custom udp-request Updated

Http custom UDP Config and udp servers

Web-udpweb-udp is a library used to establish unreliable data channels in Node/browser environments. The key goal of this project to provide a small, stable API that anyone can use to work with real-time data on the Web.The library is currently implemented as an abstraction on top of unordered and unreliable RTCDataChannels. Since WebRTC is a dependency, a WebSocket based signaling server is included with the package to facilitate connections between clients. Client/server connections are available with the help of the wrtc package.API.subscribe(subscriber: T => any)Signal.unsubscribe(subscriber: T => any)Client(options?: { url?: string })Client.connect(to?: string = "__MASTER__", options?: { binaryType?: "arraybuffer" | "blob", maxRetransmits?: number, maxPacketLifeTime?: number, metadata?: any, UNSAFE_ordered?: boolean}): PromiseClient.route(): PromiseClient.connections: SignalConnection.send(message: any): voidConnection.close(): voidConnection.closed: SignalConnection.errors: SignalConnection.messages: SignalConnection.metadata: any// NodeServer({ server: http.Server, keepAlivePeriod?: number = 30000 })Server.client(): ClientServer.connections: Signal">SignalT>.subscribe(subscriber: T => any)SignalT>.unsubscribe(subscriber: T => any)Client(options?: { url?: string })Client.connect(to?: string = "__MASTER__", options?: { binaryType?: "arraybuffer" | "blob", maxRetransmits?: number, maxPacketLifeTime?: number, metadata?: any, UNSAFE_ordered?: boolean}): PromiseConnection>Client.route(): Promisestring>Client.connections: SignalConnection>Connection.send(message: any): voidConnection.close(): voidConnection.closed: SignalConnection.errors: Signal{ err: string }>Connection.messages: Signalany>Connection.metadata: any// NodeServer({ server: http.Server, keepAlivePeriod?: number = 30000 })Server.client(): ClientServer.connections: SignalConnection>Installationnpm i @web-udp/clientnpm i @web-udp/serverExamplesClient/ServerBelow is a simple example of a ping server:// client.jsimport { Client } from "@web-udp/client"async function main() { const udp = new Client() const connection = await udp.connect() connection.send("ping") connection.messages.subscribe(console.log)} { connection.messages.subscribe(message => { if (message === "ping") { connection.send("pong") } }) connection.closed.subscribe(() => console.log("A connection closed.")) connection.errors.subscribe(err => console.log(err))})server.listen(8000)">// server.jsconst server = require("http").createServer()const { Server } = require("@web-udp/server")const udp = new Server({ server })udp.connections.subscribe(connection => { connection.messages.subscribe(message => { if (message === "ping") { connection.send("pong") } }) connection.closed.subscribe(() => console.log("A connection closed.")) connection.errors.subscribe(err => console.log(err))})server.listen(8000)MetadataThe metadata option in Client.connect is used to send arbitrary handshake data immediately after establishing a connection. When a new connection is established, the remote client can access this data on the metadata property of the connection object without having to subscribe to the remote client's messages. Handshake metadata is transmitted over a secure RTCDataChannel, making it a good candidate for sensitive data like passwords.In the below example, a server handles authentication before subscribing to the client's messages:// client.jsconst connection = await udp.connect({ metadata: { credentials: { username: "foo", password: "bar", }, },}) { let user try { user = await fakeAuth.login(connection.metadata.credentials) } catch (err) { // Authentication failed, close connection immediately. connection.send(fakeProtocol.loginFailure()) connection.close() return } // The user authenticated successfully. connection.send(fakeProtocol.loginSuccess(user)) connection.messages.subscribe(...)})">// server.jsudp.connections.subscribe(connection => { let user try { user = await fakeAuth.login(connection.metadata.credentials) } catch (err) { // Authentication failed, close connection immediately. connection.send(fakeProtocol.loginFailure()) connection.close() return } // The user authenticated successfully. connection.send(fakeProtocol.loginSuccess(user)) connection.messages.subscribe(...)})P2Pweb-udp also supports peer-to-peer communication. The below example demonstrates two clients connected in the same browser tab:">script src="/page/node_modules/@web-udp/client/dist/index.js">script>script src="client.js">script> connection.messages.subscribe(console.log), ) connection.send("HELLO")}">// client.jsasync function main() { const left = A DHCP client device acquires the IP address and the network parameters by broadcasting a UDP packet called DHCPDISCOVER within the network.Upon receiving the DHCPDISCOVER broadcast, all the non-authoritative servers discard or ignore the message. DHCP servers within the networks receive and process the broadcast packet.The DHCP Discover message contains details like: UDP Source Port 68 UDP Destination Port 67 Source IP 0.0.0.0 Destination IP 255.255.255.255 DHCPDISCOVER Packet contents Here, the source IP of the broadcast packet is 0.0.0, as the client device has not been assigned the IP address yet. With the destination IP as 255.255.255.255, the broadcast packet is sent to all the network devices, through a process called limited broadcast. Destination IP can be set to a particular subnet ID to enable a directed broadcast.Step 2: DHCP Server offers IP and network configuration parameters to client.When a valid DHCP server receives the DHCPDISCOVER broadcast message, it reserves an IP in its IP pool, and offers that IP on lease to the requesting client. It conveys its IP lease offer, the subnet mask, and default gateways to the requesting client through a DHCPOFFER message. UDP Source Port 68 UDP Destination Port 67 Source IP 192.168.31.9 Destination IP 255.255.255.255 DHCPDISCOVER Packet contents Here 192.168.31.9 is the DHCP server that offers an IP address from its pool. Traditionally, this offer message is sent to the client by specifying the clients hardware or MAC address.Step 3: Client acknowledges the required DHCP’s offer and requests the IP lease.Upon receiving a DHCPOFFER message, the client requests the assignment of the IP address offered through the DHCPOFFER message by sending a DHCPREQUEST message to the server. This message signals the DHCP server to allocate the offered IP address on lease to the client.On receiving more than one DHCPOFFER messages from the servers in the network, the client sends a DHCPREQ (DHCP Request) message only to the DHCP server whose message was received first by the client. Other offers are discarded or ignored. UDP Source Port 68 UDP Destination Port 67 Source IP 0.0.0.0 Destination IP 255.255.255.255 DHCPREQ Packet contents Step 4: DHCP Server acknowledges clients IP lease request.Upon receiving the DHCPREQUEST message, the DHCP server assigns the IP address to the client, and logs it in its data store. The server confirms the allocated IP address, subnet mask, and default gateway details by sending an DHCPACK (DHCP acknowledgement) message.The client can now start using the allocate IP and network parameters. UDP Source Port 68 UDP Destination Port 67 Source IP 192.168.31.9 Destination IP 255.255.255.255 DHCPACK Packet contents The DHCP client configures itself with the received network parameters.DHCP relay agentDevices can send broadcast messages only within the network they are a part of. They can

UDP server and UDP client - Stack Overflow

'message', //this can be anything you want so long as //your client knows. data+' world!' ); } ); ipc.server.on( 'socket.disconnected', function(socket, destroyedSocketID) { ipc.log('client ' + destroyedSocketID + ' has disconnected!'); } ); } ); ipc.server.start();Client for Unix Sockets & TCP SocketsThe client connects to the servers socket for Inter Process Communication. The socket will receive events emitted to it specifically as well as events which are broadcast out on the socket by the server. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets. import ipc from 'node-ipc'; ipc.config.id = 'hello'; ipc.config.retry= 1500; ipc.connectTo( 'world', function(){ ipc.of.world.on( 'connect', function(){ ipc.log('## connected to world ##'.rainbow, ipc.config.delay); ipc.of.world.emit( 'message', //any event or message type your server listens for 'hello' ) } ); ipc.of.world.on( 'disconnect', function(){ ipc.log('disconnected from world'.notice); } ); ipc.of.world.on( 'message', //any event or message type your server listens for function(data){ ipc.log('got a message from world : '.debug, data); } ); } );Server & Client for UDP SocketsUDP Sockets are different than Unix, Windows & TCP Sockets because they must be bound to a unique port on their machine to receive messages. For example, A TCP, Unix, or Windows Socket client could just connect to a separate TCP, Unix, or Windows Socket sever. That client could then exchange, both send and receive, data on the servers port or location. UDP Sockets can not do this. They must bind to a port to receive or send data.This means a UDP Client and Server are the same thing because in order to receive data, a UDP Socket must have its own port to receive data on, and only one process can use this port at a time. It also means that in order to emit or broadcast data the UDP server will need to know the host and port of the Socket it intends to broadcast the data to.This is the most basic example which will work for both local and remote UDP Sockets.UDP Server 1 - "World" import ipc from 'node-ipc'; ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.serveNet( 'udp4', function(){ console.log(123); ipc.server.on( 'message', function(data,socket){ ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable); ipc.server.emit( socket, 'message', { from : ipc.config.id, message : data.message+' world!' } ); } ); console.log(ipc.server); } ); ipc.server.start();UDP Server 2 - "Hello"note we set the port here to 8001 because the world server is already using the default ipc.config.networkPort of 8000. So we can not bind to 8000 while world is using it. ipc.config.id = 'hello'; ipc.config.retry= 1500; ipc.serveNet( 8001, 'udp4', function(){ ipc.server.on( 'message', function(data){ ipc.log('got Data'); ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable); } ); ipc.server.emit( { address : '127.0.0.1', //any hostname

c - UDP Client shows 'UDP Connected' while no UDP Server

+ data.complete) console.log('number of leechers in the swarm: ' + data.incomplete)})client.once('peer', function (addr) { console.log('found a peer: ' + addr) // 85.10.239.191:48623})// announce that download has completed (and you are now a seeder)client.complete()// force a tracker announce. will trigger more 'update' events and maybe more 'peer' eventsclient.update()// provide parameters to the trackerclient.update({ uploaded: 0, downloaded: 0, left: 0, customParam: 'blah' // custom parameters supported})// stop getting peers from the tracker, gracefully leave the swarmclient.stop()// ungracefully leave the swarm (without sending final 'stop' message)client.destroy()// scrapeclient.scrape()client.on('scrape', function (data) { console.log('got a scrape response from tracker: ' + data.announce) console.log('number of seeders in the swarm: ' + data.complete) console.log('number of leechers in the swarm: ' + data.incomplete) console.log('number of total downloads of this torrent: ' + data.downloaded)})serverTo start a BitTorrent tracker server to track swarms of peers:const Server = require('bittorrent-tracker').Serverconst server = new Server({ udp: true, // enable udp server? [default=true] http: true, // enable http server? [default=true] ws: true, // enable websocket server? [default=true] stats: true, // enable web-based statistics? [default=true] trustProxy: false, // enable trusting x-forwarded-for header for remote IP [default=false] filter: function (infoHash, params, cb) { // Blacklist/whitelist function for allowing/disallowing torrents. If this option is // omitted, all torrents are allowed. It is possible to interface with a database or // external system before deciding to allow/deny, because this function is async. // It is possible to block by peer id (whitelisting torrent clients) or by secret // key (private trackers). Full access to the original HTTP/UDP request parameters // are available in `params`. // This example only allows one torrent. const allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa') if (allowed) { // If the callback is passed `null`, the torrent will be allowed. cb(null) } else { // If the callback is passed an `Error` object, the torrent will be disallowed // and the error's `message` property will be given as the reason. cb(new Error('disallowed torrent')) } }})// Internal http, udp, and websocket servers exposed as public properties.server.httpserver.udpserver.wsserver.on('error', function (err) { // fatal server error! console.log(err.message)})server.on('warning', function (err) { // client sent bad data. probably not a problem, just a buggy client. console.log(err.message)})server.on('listening', function () { // fired when all requested servers are listening // HTTP const httpAddr = server.http.address() const httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost' const httpPort = httpAddr.port console.log(`HTTP tracker: // UDP const udpAddr = server.udp.address() const udpHost = udpAddr.address const udpPort = udpAddr.port console.log(`UDP tracker: udp://${udpHost}:${udpPort}`) // WS const wsAddr = server.ws.address() const wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost' const wsPort = wsAddr.port console.log(`WebSocket tracker: ws://${wsHost}:${wsPort}`)})// start tracker server listening! Use 0 to listen on a random free port.const port = 0const hostname = "localhost"server.listen(port, hostname, () => { //. Download Udp Server; Udp Client Server; Udp Socket Server; Boost Udp Server; Udp Udp Download; Udp Download Test; Udp Software Download; Download Udp Server Software. Voltssh-X - UDP Management Script ssh script panel udp vps vpn-server udp-server dropbear udp-client ssh-manager udp-client-server udp-custom udp-request Updated

Udp Client Server - FREE Download Udp Client Server 1.1.3

_ ___ _____| |__ _ _ __| |_ __ \ \ /\ / / _ \ '_ \| | | |/ _` | '_ \ \ V V / __/ |_) | |_| | (_| | |_) | \_/\_/ \___|_.__/ \__,_|\__,_| .__/ |_|WebUDPNOTE: This is highly experimental and the API will be changeWebUDP is a thin wraper on top of WebRTC. WebUDP tries to mimic the WebSocket API as much as possible at least on the client side.Signaling server/client are built on top of noraml http/fetch to make it super portable and light weight.InstallationUsageWebUDP comes with both server and client class which simplified the complexity of using WebRTC.WebUDPServerextends WebUDPServer and implement one or more of onLeave, onJoin, onError or onMessage.Also send(id, data), sendAll(data) and close(id) method are provided by WebUDPServer. { this.send(id, 'hello from UDP server again') }, 1000) }}new WebUDP(8001)">const WebUDPServer = require('webudp/server')//class WebUDP extends WebUDPServer { constructor(port) { super({ port: port }) } onLeave(id) { console.log('leave: ', id) } onJoin(id) { console.log('join: ', id) this.send(id, 'hello from UDP server') } onError(id, err) { console.log('error: ', id, err) } onMessage(id, data) { console.log('data: ', id, data) setTimeout(() => { this.send(id, 'hello from UDP server again') }, 1000) }}new WebUDP(8001)WebUDPClientClient side there are four(4) methods to implements. send(data) and close() are also provided by WebUDPClient { this.close() }, 5000) } onError(err) { console.log('error: ', err) } onMessage(data) { console.log('data', data) setTimeout(() => { this.send('hello from UDP client again') }, 1000) }}const webUDP = new WebUDP(' WebUDP extends WebUDPClient { constructor(addr)

Comments

User7419

F1-22 Updated May 22, 2023 TypeScript luka2220 / dns-resolver-api Star 1 Code Issues Pull requests A simple API that can resolve the IP address for a host nodejs dns network-programming udp-client rfc1035 Updated Dec 24, 2024 TypeScript paranlee / deno-tcp-udp Star 1 Code Issues Pull requests Use Deno as TCP/UDP server. typescript tcp daemon udp tcp-server tcp-client udp-server udp-client deno Updated Aug 17, 2021 TypeScript ablomer / satisfactory-server-status Star 0 Code Issues Pull requests 🎮 A real-time server status monitor for Satisfactory dedicated servers that leverages UDP polling and WebSocket connections for efficient state tracking. docker dashboard websocket udp socket-io node-js udp-client satisfactory Updated Jan 18, 2025 TypeScript Improve this page Add a description, image, and links to the udp-client topic page so that developers can more easily learn about it. Curate this topic Add this topic to your repo To associate your repository with the udp-client topic, visit your repo's landing page and select "manage topics." Learn more

2025-04-01
User6838

I am often asked to measure the bandwidth of a network path. Many users test this using a simple HTTP download or with speedtest.net. Unfortunately, any test using TCP will produce inaccurate results, due to the limitations of a session-oriented protocol. TCP window size, latency, and the bandwidth of the return channel (for ACK messages) all affect the results. The most reliable way to measure true bandwidth is with UDP. That’s where my friends iperf and bwm-ng come in handy.iperf is a tool for measuring bandwidth and reporting on throughput, jitter, and data loss. Others have written handy tutorials, but I’ll summarise the basics here.iperf will run on any Linux or Unix (including Mac OSX), and must be installed on both hosts. Additionally, the “server” (receiving) host must allow incoming traffic to some port (which defaults to 5001/UDP and 5001/TCP). If you want to run bidirectional tests with UDP, this means you must open 5001/UDP on both hosts’ firewalls.iptables -I INPUT -p udp -m udp --dport 5001 -j ACCEPTA network path is really two paths – the downstream path and the upstream (or return) path. With iperf, the “client” is the transmitter and the “server” is the receiver. So we’ll use the term “downstream” to refer to traffic transmitted from the client to the server, and “upstream” to refer to the opposite. Since these two paths can have different bandwidths and entirely different routes, we should measure them separately.Start by opening terminal windows to both the client and server hosts, as well as the iperf man page. On the server, you only have to start listening. This runs iperf as a server on the default 5001/UDP.root@server:~# iperf -s -u------------------------------------------------------------Server listening on UDP port 5001Receiving 1470 byte datagramsUDP buffer size: 124 KByte (default)------------------------------------------------------------The server will output test results, as well as report them back to the client for display.On the client, you have many options. You can push X data (-b) for Y seconds (-t). For example, to push 1 mbit for 10 seconds:root@client:~# iperf -u -c server.example.com -b 1M -t 10------------------------------------------------------------Client connecting to 172.16.0.2, UDP port 5001Sending 1470 byte datagramsUDP

2025-04-17
User4154

UDP Hole-PunchingPurposeHave a server negotiate a peer-to-peer connection between two clients in the most direct way possible.Demonstrate Hole-Punching / NAT traversal using the UDP protocol.Demonstrate the support of UPnP.MethodServer:Uses TCP to manage available clients.Uses UDP to learn the public End Point (IP and Port) of clients.Publishes list of connected clients and their End Points.Relays connection requests between clients.Client:Attempts to use UPnP to forward a port to itself on the router (Optional).Sends the server the following information:Hostname (as a friendly name)Whether UPnP is enabled or not.Local UDP port that the client is listening on.List of local IP addresses.Sends a message to the server that it wishes to connect to another client / Receives a message from the server that another client wishes to connect to it. (Both clients will attempt to connect to each other at the same time)Sends 3 ACK requests to each local IP of other client to determine if clients are on the same LAN.If there was no response, sends 99 ACK requests to public/external End Point.If UDP Hole-Punching is successful, a chat window will be shown and a conversation can begin.Everything the client attempts is outputted to a textbox for review.InstructionsRun the GetConnected server executable on a publicly reachable server. (Forward TCP and UDP port to your server on your router.)Change value 'ServerEndpoint' in Client.cs to your servers public IP.Run the P2PClient executable on PCs you want to connect.Click the 'Connect' button in the top left to connect to the server. The server will ensure you always have an updated list of available clients.Select a client and click 'Connect' in the bottom right to connect to it.Observe as two clients begin to establish a connect to each other.

2025-04-04
User6759

Web-udpweb-udp is a library used to establish unreliable data channels in Node/browser environments. The key goal of this project to provide a small, stable API that anyone can use to work with real-time data on the Web.The library is currently implemented as an abstraction on top of unordered and unreliable RTCDataChannels. Since WebRTC is a dependency, a WebSocket based signaling server is included with the package to facilitate connections between clients. Client/server connections are available with the help of the wrtc package.API.subscribe(subscriber: T => any)Signal.unsubscribe(subscriber: T => any)Client(options?: { url?: string })Client.connect(to?: string = "__MASTER__", options?: { binaryType?: "arraybuffer" | "blob", maxRetransmits?: number, maxPacketLifeTime?: number, metadata?: any, UNSAFE_ordered?: boolean}): PromiseClient.route(): PromiseClient.connections: SignalConnection.send(message: any): voidConnection.close(): voidConnection.closed: SignalConnection.errors: SignalConnection.messages: SignalConnection.metadata: any// NodeServer({ server: http.Server, keepAlivePeriod?: number = 30000 })Server.client(): ClientServer.connections: Signal">SignalT>.subscribe(subscriber: T => any)SignalT>.unsubscribe(subscriber: T => any)Client(options?: { url?: string })Client.connect(to?: string = "__MASTER__", options?: { binaryType?: "arraybuffer" | "blob", maxRetransmits?: number, maxPacketLifeTime?: number, metadata?: any, UNSAFE_ordered?: boolean}): PromiseConnection>Client.route(): Promisestring>Client.connections: SignalConnection>Connection.send(message: any): voidConnection.close(): voidConnection.closed: SignalConnection.errors: Signal{ err: string }>Connection.messages: Signalany>Connection.metadata: any// NodeServer({ server: http.Server, keepAlivePeriod?: number = 30000 })Server.client(): ClientServer.connections: SignalConnection>Installationnpm i @web-udp/clientnpm i @web-udp/serverExamplesClient/ServerBelow is a simple example of a ping server:// client.jsimport { Client } from "@web-udp/client"async function main() { const udp = new Client() const connection = await udp.connect() connection.send("ping") connection.messages.subscribe(console.log)} { connection.messages.subscribe(message => { if (message === "ping") { connection.send("pong") } }) connection.closed.subscribe(() => console.log("A connection closed.")) connection.errors.subscribe(err => console.log(err))})server.listen(8000)">// server.jsconst server = require("http").createServer()const { Server } = require("@web-udp/server")const udp = new Server({ server })udp.connections.subscribe(connection => { connection.messages.subscribe(message => { if (message === "ping") { connection.send("pong") } }) connection.closed.subscribe(() => console.log("A connection closed.")) connection.errors.subscribe(err => console.log(err))})server.listen(8000)MetadataThe metadata option in Client.connect is used to send arbitrary handshake data immediately after establishing a connection. When a new connection is established, the remote client can access this data on the metadata property of the connection object without having to subscribe to the remote client's messages. Handshake metadata is transmitted over a secure RTCDataChannel, making it a good candidate for sensitive data like passwords.In the below example, a server handles authentication before subscribing to the client's messages:// client.jsconst connection = await udp.connect({ metadata: { credentials: { username: "foo", password: "bar", }, },}) { let user try { user = await fakeAuth.login(connection.metadata.credentials) } catch (err) { // Authentication failed, close connection immediately. connection.send(fakeProtocol.loginFailure()) connection.close() return } // The user authenticated successfully. connection.send(fakeProtocol.loginSuccess(user)) connection.messages.subscribe(...)})">// server.jsudp.connections.subscribe(connection => { let user try { user = await fakeAuth.login(connection.metadata.credentials) } catch (err) { // Authentication failed, close connection immediately. connection.send(fakeProtocol.loginFailure()) connection.close() return } // The user authenticated successfully. connection.send(fakeProtocol.loginSuccess(user)) connection.messages.subscribe(...)})P2Pweb-udp also supports peer-to-peer communication. The below example demonstrates two clients connected in the same browser tab:">script src="/page/node_modules/@web-udp/client/dist/index.js">script>script src="client.js">script> connection.messages.subscribe(console.log), ) connection.send("HELLO")}">// client.jsasync function main() { const left =

2025-03-31

Add Comment