2

Please read my question,even a small piece of advice will be received with gratitude.

I am getting the following error in Google Chrome:

 GET http://localhost/socket.io/?EIO=3&transport=polling&t=1419089743449-2 404 (Not Found)

My folder setup is as follows:

localhost

pro

public

socket.io/socket.io.js

cssfile.css

jsfile.js

app.js

node_ modules

It seems to me that the request made by the client for the handshake is wrong because the error should be localhost/pro/public/socket.io/blah blah .

I am using the following setup:

web.config :

<handlers>
 <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
 <rules>
  <rule name="DynamicContent">
   <match url="/pro/" negate='True'/>
   <!--<conditions>
    <add input="pro" matchType="IsFile" negate="True"/>
   </conditions>-->
   <action type="Rewrite" url="app.js"/>
 </rule> 
 <rule name="LogFile" patternSyntax="ECMAScript">
  <match url="socket.io"/>
  <action type="Rewrite" url="app.js"/>
 </rule>               
</rules>
</rewrite>

client side js:

 var socket = io.connect('http: //localhost', {resource: 'pro/public/socket.io' }); 

server side js(node):

 var http = require('http');

 var express = require('express');
 var app = express();
 var port = process.env.PORT || 3002;

 var server = http.createServer(app).listen(port);

 io = require('socket.io').listen(server, { resource : '/pro/public/socket.io' });

I get html as expect and the static files are served as well; I just can't get socket.io to work.

drizo
  • 267
  • 6
  • 14
  • 1
    I am pretty sure your client side JS needs to direct the socket to connect on whichever port you are serving off of. So, for instance `var socket = io.connect('http://localhost:3002', {resource: 'pro/public/socket.io'});`. – Joshua Dec 22 '14 at 19:25
  • Thank you Joshua, let me try and answer back to you. – drizo Dec 22 '14 at 21:08
  • @Joshua It doesn't seem to work. My problem is that whatever I use at io.connect(..,resource = blah blah) it won't search in the resource link provided! Why is that?! I am going crazy! – drizo Dec 22 '14 at 21:26
  • @Joshua Seems to me that there is something wrong with the web.config file! Whatever I use at resource: ... it won't count. – drizo Dec 22 '14 at 21:33
  • Unfortunately, I am not familiar with IISNode, so I don't think I can help much. However, I did notice that the `resource` might need to be renamed to `path`, as identified here, under "Setting resource path": http://socket.io/docs/migrating-from-0-9/ – Joshua Dec 23 '14 at 09:28

2 Answers2

2

SOLUTION:

CHANGE :

io = require('socket.io').listen(server, { resource : '/pro/public/socket.io' });

TO

io = require('socket.io').listen(server, { path : '/pro/public/socket.io' });

THAT is what worked for me I hope it works for you too! :)

drizo
  • 267
  • 6
  • 14
0

Drizo, I think your 404 on the socket.io is a mixture of things, but I'm not a huge expert here! :)

Firstly, the port is missing from your connection string, you'll need this.

Secondly, I'm not 100% sure your socket.io initialisation is correct, though I use namespaces and hadn't heard of resources before, mine looks something like:

var app = require('express')();
var http = require('http').Server(app);
var config = require('./config')();

var server = http.listen(config.server.port, function () {
  console.log('listening on *:' + config.server.port);
});

var socketIo = require('socket.io');
var io = socketIo(http);
var namespaceIo = io.of('/namespace');
namespaceIo.on('connection', function (socket) {
   //configuration for events follows
   socket.on('someEvent', function (input) {
       ...
   }
}

With these lines you can namespace out a socket.io implementaton, and the client can connect with something like

function initSocket(__bool){     

    if(__bool == true){
        io(serverAddress + '/namespace');
        if ( !socket ) {   
            socket = io.connect(serverAddress + '/namespace');
        } else {
            socket.socket.connect(serverAddress + '/namespace'); // Yep, socket.socket ( 2 times )
        }

        // now that we have the socket we can bind events to it
        bindSocketEvents();
    }else{
        socket.disconnect();
    }
} 
Mark Beeby
  • 11
  • 1
  • 3