javascript - Show random numbers on html sent from Node.js -


I'm trying to show a random number for a file named display.html in node.js and show it on port 3000 . When I run the node code in server.js, I get the confirmation that the data is transmitting, but I do not see anything on the local host: 3000. I am using node.js Express version 4.7.1 and socket.io version 1.0.6.

Thanks in advance!

  requires the app = ('Express') (); Var http = Required ('http'). Server (app); Var io = Requirement ('socket.io') (HT); App.get ('/', function (rik, ridge) {res.sendfile ('display.html');}); Io.on ('connection', function (socket) {console.log ('user connect');}); SetInterval (function () {console.log ('emitting'); io.emit ('coordinate', {x: Math.random (), y: Math.random (), z: Math.random ()}); }, 3000); Http.listen (3000, function () {console.log ('listen to *: 3000');});  

Here is html where I get the data:

  & lt; Html & gt; & Lt; Body & gt; & Lt; Ul & gt; & Lt; / Ul & gt; & Lt; Script src = "https://cdn.socket.io/socket.io-1.0.6.js" & gt; & Lt; / Script & gt; & Lt; Script src = "http://code.jquery.com/jquery-1.11.1.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Var Socket = Io ('192.734 .....: 3000'); Socket.on ('coordinate', function (obje) {$ ('ul'). Append ($ ('
  • ;). Text (JSON.stringify (obj));}); Onociding io.emit ('Coordination' .., OBG) & lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
  • Try changing your HTML for:

      & lt; Html & gt; & Lt; Body & gt; & Lt; Ul & gt; & Lt; / Ul & gt; & Lt; Script src = "https://cdn.socket.io/socket.io-1.0.6.js" & gt; & Lt; / Script & gt; & Lt; Script src = "http://code.jquery.com/jquery-1.11.1.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Var socket = Io ('127.0.0.1:3000'); Socket.on ('coordinate', function (obje) {$ ('ul'). Append ($ ('
  • ;). Text (JSON.stringify (obj));}); & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
  • The last two lines of the script are throwing a syntax error on the browser:

      Onkoording io.emit ('Coordination' .., OBG)  

    Comments

    Popular posts from this blog

    java - org.apache.http.ProtocolException: Target host is not specified -

    java - Gradle dependencies: compile project by relative path -

    ruby on rails - Object doesn't support #inspect when used with .include -