node.js - Socket.io Chat Tutorial not functioning properly -


So I end up in the node. Decided to give a shot to JS I decided to go with a small chat app to break ice. The tutorial I follow is directly from the socket.io site.

I am following the word tutorial for the word and also attempted to copy and paste the code into the source and I can not find any place when I read I type in and send it. This is going to come in my command prompt, though it is not.

I was connected to the user and the users were able to see the disconnected messages, but I'm stumped because I have stepped through the tutorial step.

Index.js

  requires the app = ('Express') (); Var http = Required ('http'). Server (app); Var io = Requirement ('socket.io') (HT); app.get ('/', function (rick, ridge) {res.sendFile ('/ chat / index.html');}); Io.on ('connection', function (socket) {socket.on ('chat message', function (msg) {console.log ('message:' + msg);});}); Http.listen (3000, function () {console.log ('Hearing *: 3000');});   

index.html:

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Head lang = "en" & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Title & gt; Chat and lt; / Title & gt; & Lt; Script src = "/ socket.io/socket.io.js"></script> & Lt; Script src = "http://code.jquery.com/jquery-1.11.1.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Var Socket = Io (); $ ('Form') Submit (function () {socket.emit ('chat message', $ ('# m'). Val ()); $ ('# m'). Val (''); return false;}); & Lt; / Script & gt; & Lt; Style & gt; * {Margin: 0; Padding: 0; Box-size: border-box; } Body {font: 13 px helvetica, aerial; } Form {background: # 000; Padding: 3px; Status: fixed; Bottom: 0; Width: 100%; } Form Input {limit: 0; Padding: 10px; Width: 90%; Margin-right: .5%; } Form Button {Width: 9%; Background: RGB (130, 224, 255); Border: None; Padding: 10px; } # Messages [list-style-type: none; Margin: 0; Padding: 0; } #Send Message {Padding: 5px 10px; } # Message taken: nth-child (strange) {background: #eee; } & Lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Ul id = "message" & gt; & Lt; / Ul & gt; & Lt; Form action = "" & gt; & Lt; Input id = "m" autocomplete = "off" /> & Lt; Button & gt; Send & lt; / Button & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

I'm assuming that I was blown up some place but I did not see it, even though I tried and copied and pasted it. In addition, if it matters that I am using Windows 8.1 and Chrome. I checked around and got the answer to this problem too. Any help would be great.

EDIT: The problem was with Jacques, for some reason it is not responding as much as it needs. After rewriting the script in vanilla, it works with the purpose.

Index.js - JavaScript

  & lt; Script & gt; Var Socket = Io (); Function sendMessage () {var msg = document.getElementById ('m'); Socket.emit ('message', msg.value); Msg.value = ''; return false; } & Lt; / Script & gt;   

HTML:

  & lt; Form action = "" onsubmit = "javascript: sendMessage ();" & Gt; & Lt; Input id = "m" autocomplete = "off" /> & Lt; Button & gt; Send & lt; / Button & gt; & Lt; / Form & gt; You can activate logging for Socket.IO in Chrome by typing in your console:    

localStorage.debug = "socket.io-client: socket"

and on the server side:

  debug = * node Yourfile.js   

In addition, when you have a document ready to execute the script, you will have to delay a short while to use jQuery:

  $ (document) .ready (function () {var socket = io (); $ ('form'). Submit (function () {socket.emit ( 'chat message', $ ('# M'). Val ()); $ ('# m'). Val (''); return false;});});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -