0

I am developing a WebGL multiplayer game. I try to implement multiplayer by socket.io, with express in node.js. When the user presses any key, the key event is first sent to server then the server should broadcast using socket to all the clients, like when the user presses key, the movement of the character should be visible to all of the client's browsers, but however right now with my code only the browser in which the client presses key the movement of character occurs.

I have provided my code here

https://github.com/kshitizrimal/helpGl

Please help me with this situation

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
monk
  • 4,727
  • 13
  • 45
  • 67

1 Answers1

0

You are using express 2.x syntax. You must change the syntax for express v3. See this page

Socket.IO's .listen() method takes an http.Server instance as an argument. As of 3.x, the return value of express() is not an http.Server instance. (See the Application function section above.) To get Socket.IO working with Express 3.x, make sure you manually create and pass your http.Server instance to Socket.IO's .listen() method.

This is how you would do it with express3 and socket.io

var express = require('express')
var http = require('http');
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
user568109
  • 47,225
  • 17
  • 99
  • 123