Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Asignar valor a una variable y enviarlo al servidor NodeJS

Estoy tratando de asignar un valor a una variable obteniendo la entrada del formulario html y luego enviándola a mi servidor node js, pero el problema es que cuando se fija el valor, el servidor lo muestra bash en la página html desde donde vino. Cuando trato de obtener el valor del formulario, solo obtiene una cadena vacía. aquí está el código para el servidor html y node js.

 // Node.js WebSocket server script const http = require('http'); const WebSocketServer = require('websocket').server; const server = http.createServer(); console.log('Server is on port 3000') server.listen(3000); const wsServer = new WebSocketServer({ httpServer: server }); wsServer.on('request', function(request) { const connection = request.accept(null, request.origin); connection.on('message', function(message) { var test=message.utf8Data; console.log('Received Message:', test); connection.sendUTF(test); }); connection.on('close', function(reasonCode, description) { console.log('Client has disconnected.'); }); });
 <?php ob_start() ?> <?php $titel="Chat"; ?> <div class="chat-main" id="text"></div> <form name='form' method='post' class="form"> <div class="form-group"> <input type="text" class="form-control" id="textbox" name="chat" placeholder="Chat"> <button type="submit" class="btn btn-primary" name="gumb" id="gumb">Send</button> </div> </form> <script> const ws = new WebSocket('ws://localhost:3000'); var message="This is the client speaking."; console.log(message); ws.onopen = function() { console.log('WebSocket Client Connected'); ws.send(message); }; ws.onmessage = function(e) { console.log("Received: '" + e.data + "'"); document.getElementById('text').innerHTML=e.data; }; </script> <?php $content=ob_get_clean(); require "layout.html.php"; ?>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!