1.2.1 • Published 3 years ago

udplus v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

udplus

⚠️ WORK IN PROGRESS ⚠️

This Package offers a simple and easy to set up wrapper around Nodes internal "dgram" Module. It offers server and client side Functions. The API is inspired by the "Socket.io" Package.

Creating a Server

const  udplus = require("udplus")
const  server = udplus.createServer(port)

server.listen(3000, info  => {
	console.log("listening on: " + info);
})

client.on("connection", info  => {
	console.log(info);
})

Connecting Client to local Server

const  udplus = require("udplus")
const  client = udplus.createClient()

client.connect("localhost", 3000, info  => {
    console.log("connected!", info);
})

Sending and Recieving data on Server

//emits for each connected client
server.on("connection", client  => {
	console.log("client connected: ", client.address);
	
	//Recieve data from THIS client
	client.on("custom-event", data  => {
		console.log(data);
	})
	
	//send data to THIS client
	client.emit("custom-event", data)
})

Sending and Recieving data on Client

//send from client to server
client.emit("custom-event", "Hello World")

//recieve from server
client.on("test", data  => {
	console.log(data);
})
1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago