I am new to node, express and socket.io. I am trying to build a game using these technology.. I have global.js which i am using as server side. every action from client side to side or vice versa works fine. Now i am trying to build a computre player. So I have created bot.js file in server end. I am getting connection successfull in console whenever i create new computer player with different client id. But when i try to emit a task ('joinTable') no response i can see. I will be greatfull if someon help me to solve this. Any suggestion is also fine
<pre>bot.js serverside file
var io = require( 'socket.io-client' ); function bot( client ) { this.socket = {}; this.createBot = function ( ) { this.socket = io.connect( "http://192.45.47.44:3000", { "force new connection": true } ); } this.createBot( ); this.socket.on( 'connectionSuccess', function ( args ) { console.log( 'connection successfull for ', args.id ) client.emit( 'joinTable', args ); } ); return this; } function computerPlayer( ) { return { createBot: function ( client ) { var botPlayer = new bot( client ); return botPlayer; } } } module.exports = new computerPlayer( );
global.js server side file ( same file I am using for client-side also )
var io = require( 'socket.io' ); var computerPlayer = require( './bot' ); function Io( ) { return { init: function ( server ) { var objServ = io.listen( server ); objServ.sockets.on( 'connection', function ( client ) { computerPlayer.createBot( client ); client.on( 'joinTable', function ( args ) { console.log( 'joinTable client id', args.id ); } ); client.emit( 'connectionSuccess', { id: client.id } ); } ); } } } module.exports = new Io( );
I fixed it... I used
var soc = this.socket = io.connect( ip, { "force new connection": true } );
...........
soc.emit('joinTable', args); //instead of using client i used soc.emit() in bot.js
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)