Answer the question
In order to leave comments, you need to log in
How to do processing in node.js?
Hello!
Here is the nodeJS code
Here is the server itself:
var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );
var app = express();
var server = http.createServer( app );
var io = socket.listen( server );
io.sockets.on( 'connection', function( client ) {
console.log( "New client !" );
client.on( 'message', function( data ) {
console.log( 'Message received ' + data.name + "1" + data.message + data.canal );
//client.broadcast.emit( 'message', { name: data.name, message: data.message } );
io.sockets.emit( 'message', { name: data.name, message: data.message, canal: data.canal } );
});
});
server.listen( 8080 );
var socket = io.connect( 'http://localhost:8080' );
$( "#messageForm" ).submit( function() {
var nameVal = $( "#nameInput" ).val();
var msg = $( "#messageInput" ).val();
var canalVal = $( "#canalInput" ).val();
if((nameVal) && (msg)){
socket.emit( 'message', { name: nameVal, message: msg, canal: canalVal } )};
// Ajax call for saving datas
$.ajax({
url: "./ajax/insertNewMessage.php",
type: "POST",
data: { name: nameVal, message: msg, canal: canalVal },
success: function(data) {
}
});
return false;
});
socket.on( 'message', function( data ) {
var actualContent = $( "#messages" ).html();
var newMsgContent = '<li> <strong>' + data.name + '</strong> : ' + data.message + '</li>';
var content = newMsgContent + actualContent;
$( "#messages" ).html( content );
});
Answer the question
In order to leave comments, you need to log in
I don't understand where the comments went! !! The question
is str.replace(new RegExp("blabla",'gi'),"bloblo") is this construction very heavy?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question