iisnode icon indicating copy to clipboard operation
iisnode copied to clipboard

Socket.io response code 200 instead 101

Open YegorMedvedev opened this issue 8 years ago • 6 comments

Hi!

When I try to use socket.io and Express with IISnode is have a problem, websocket connection return status 200 instead 101.

Socket.io version: 1.4.5 IIS node: 0.2.21

server code:

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

// socket.io ver 1.4.5
var server = require('http').Server(app);
var io = require('socket.io', {path: '/api/socket.io'})(server);

server.listen(port);

io.on('connection', function (socket) {
    socket.emit('test', { hello: 'world' });
});

app code (angular 2):

var address = 'http://xxx.xxx.xxx.xxx:8080/'; // ip address
var socket = io.connect(address, {transports: ['websocket'], path: '/api/socket.io'});    
socket.on('test', (data) => {
    console.log(data, '<-- socket data');
})

web.config

<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
            <!-- <add name="iisnode-socket.io" path="index.js" verb="*" modules="iisnode" /> -->
        </handlers>

        <rewrite>
            <rules>
                <rule name="LogFile" patternSyntax="ECMAScript">
                    <match url="socket.io"/>
                    <action type="Rewrite" url="index.js"/>
                </rule>
                <rule name="api">
                    <match url="/*"/>
                    <action type="Rewrite" url="index.js"/>
                </rule>
            </rules>
        </rewrite>

        <iisnode
            devErrorsEnabled="true"/>
        <webSocket enabled="false" />
    </system.webServer>
</configuration>

And, then I run this app as static on same server I've got 200 status of response and this error in console: WebSocket connection to 'ws://xxx.xxx.xxx.xxx:8080/api/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 200

What I do wrong?

YegorMedvedev avatar Apr 14 '16 12:04 YegorMedvedev

Hi Tomek/Carl, Having the same issue with the new version of socket.io (1.4.6). Did you make it finally working? If yes, can you share your solution?

Thanks, Yuri.

ymospan avatar May 12 '16 14:05 ymospan

Guys,

Same issue here even with the 1.5.x

Any updates?

alihalabyah avatar Oct 11 '16 18:10 alihalabyah

I'm also having the same problem...

laptou avatar May 28 '17 06:05 laptou

I am using socket.io 2.0.2 and iisnode 0.2.21 and also having the same problem. Has anyone made this work?

jjmmontemayor avatar Jun 08 '17 06:06 jjmmontemayor

same here 2.0.3 but when downgrades to 1.3.5 everything fine. Interesting thing noticed: when upgrades back to 2.0.3 it still works fine. I have confirmed this several times even on prod sever.

gusarov avatar Jul 22 '17 23:07 gusarov

Same issue here on v4.3.1. I am using ELB on AWS and am wondering if it is not relaying properly (?)

joetidee avatar Nov 10 '21 20:11 joetidee