Dgram data to webpage

Joined
May 24, 2022
Messages
5
Reaction score
0
i know i am missing something simple but i need to have My console output be displayed in a webpage with express and ejs can anyone help me out

JavaScript:
import express from "express";
import dgram from "dgram";

const socketServer = dgram.createSocket("udp4");
const app = express();

app.get("/", (req, res) => {
  //res.send("Hello World!");
});

socketServer.on("message", (msg, rinfo) => {
  console.log(`got messsage from ${rinfo.address}, data: ${msg}`);
});

app.listen(5000, () => {
  socketServer.bind(5000);
  console.log(`Backend started!`);
});
 
Joined
May 24, 2022
Messages
5
Reaction score
0
here is the Working code an output, i need this to a webpage . thanks all
JavaScript:
const express = require('express')
const port = 4000
const dgram = require('dgram');

// const server = dgram.createSocket('udp4');
const socketServer = dgram.createSocket("udp4");
const app = express();

app.get("/", (req, res) => {
  //res.send("Hello World!");
});

socketServer.on("message", (msg, rinfo) => {
  console.log(`got messsage from ${rinfo.address}, data: ${msg}`);
});

app.listen(4000, () => {
  socketServer.bind(4000);
  console.log(`Backend started!`);
});
 

Attachments

  • pic1.PNG
    pic1.PNG
    4.7 KB · Views: 16
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Why are you using dgram instead of pure socket.io?
Unfortunately i don't know anything about dgram. I've read about it. Seems like Socket.io also uses dgram by default.
No clue
 
Joined
May 24, 2022
Messages
5
Reaction score
0
From a browser client, socket.io uses either the http or the webSocket transport. Both http and webSocket are TCP connections, not UDP connections. So the browser client socket.io does not use UDP - it uses TCP.
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
What is your point? Do you need something like Browser Realtime Chat / or Videochat? Than socket.io should be your choice.
As i said. I only read a little about dgram because of this thread. Never came along it earlier.
 
Joined
May 24, 2022
Messages
5
Reaction score
0
so the whole Point of the project is to read a UDP String Coming from a Remote Device on the Network in the Form of 2343,12321,0,0,0 UDP port 10000 and place the Data into a webpage.
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Okay. Isn't dgram documentation telling you anything about a connection? Your web client have to connect one way or the other.

Or, which is also a way, open your browser with the right url like yourdomain.com:5000. If everything is right your browserconsole should show the ouptut of your console.logs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,920
Messages
2,570,038
Members
46,449
Latest member
onedumbsquirrel

Latest Threads

Top