User Tools

Site Tools


tanszek:oktatas:iss_t:group_chat_-_nodejs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tanszek:oktatas:iss_t:group_chat_-_nodejs [2024/04/07 15:05] – created superusertanszek:oktatas:iss_t:group_chat_-_nodejs [2024/04/07 15:06] (current) superuser
Line 1: Line 1:
 ===== HTML - Javascript client ===== ===== HTML - Javascript client =====
 +
 +index.html
  
 <sxh html> <sxh html>
Line 39: Line 41:
 </sxh> </sxh>
  
 +===== NodeJs - server =====
 +
 +index.js
 +
 +<sxh javascript>
 +var app = require('express')();
 +var http = require('http').Server(app);
 +var io = require('socket.io')(http);
 +
 +app.get('/', function(req, res){
 +  res.sendFile(__dirname + '/index.html');
 +});
 +
 +io.on('connection', function(socket){
 +  socket.on('chat message', function(msg){
 +    io.emit('chat message', msg);
 +  });
 +});
 +
 +http.listen(3000, function(){
 +  console.log('listening on *:3000');
 +});
 +</sxh>
tanszek/oktatas/iss_t/group_chat_-_nodejs.1712502337.txt.gz · Last modified: 2024/04/07 15:05 by superuser