Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

This socket.io server do not support websocket protocol. Terminating connection... #2

Closed
Pitel opened this issue Nov 2, 2012 · 5 comments

Comments

@Pitel
Copy link
Contributor

Pitel commented Nov 2, 2012

The following code ends with this exception:

require_once('ElephantIO/Client.php');
$elephant = new ElephantIO\Client('http://localhost:8000', $debug = true);
$elephant->init(true);

But it's not true! The following JS code works just fine in browser, and I am sure (from Chrome dev tools) it uses websocket protocol:

var socket = io.connect("http://localhost:8000");
socket.on("connect", function() {
    console.log("Connected!");
});

And here is the Node.js server:

var io = require("socket.io").listen(8000);
io.configure(function() {
    io.set("log level", 2);
    io.enable("browser client minification");
    io.enable("browser client etag");
    io.enable("browser client gzip");
});

So why am I getting the above exception?

@gmajoulet
Copy link
Contributor

Can you please post the exception you had ?

@Pitel
Copy link
Contributor Author

Pitel commented Nov 2, 2012

PHP Notice:  Undefined offset: 1 in xxx/ElephantIO/Client.php on line 238
PHP Notice:  Undefined offset: 2 in xxx/ElephantIO/Client.php on line 239
PHP Notice:  Undefined offset: 3 in xxx/ElephantIO/Client.php on line 240
PHP Fatal error:  Uncaught exception 'Exception' with message 'This socket.io server do not support websocket protocol. Terminating connection...' in xxx/ElephantIO/Client.php:242
Stack trace:
#0 xxx/ElephantIO/Client.php(51): ElephantIO\Client->handshake()
#1 xxx/client.php(6): ElephantIO\Client->init(true)
#2 {main}
  thrown in xxx/ElephantIO/Client.php on line 242

PHP 5.4.6-1ubuntu1 (cli) (built: Aug 22 2012 21:13:52)

@guillaumepotier
Copy link
Member

Hi @Pitel , thanks for tryin' elephant.io!

We updated a bit the lib (2.0 tag) and unfortunately did not update the doc accordingly..

Could you please try these code parts and tell me if it works for you?

PHP Code trying to communicate with socket.io through PHP:

<?php

require('lib/ElephantIO/Client.php');
use ElephantIO\Client as ElephantIOClient;

$elephant = new ElephantIOClient('http://localhost:8000', 'socket.io', 1, false, true, true);

$elephant->init();
$elephant->send(
    ElephantIOClient::TYPE_EVENT,
    null,
    null,
    json_encode(array('name' => 'action', 'args' => 'foo'))
);
$elephant->close();

echo 'tryin to send `foo` to the event called action';

Node.js server

var io = require('socket.io').listen(8000);

io.sockets.on('connection', function (socket) {
  console.log('user connected');

  socket.on('action', function (data) {
    console.log('here we are in action event and data is: ');
    console.log(data);
  });
});

@Pitel
Copy link
Contributor Author

Pitel commented Nov 2, 2012

Oops, my bad. It seems PHP does not allow settings parameters like Python. Removing $debug = true from the constructor makes it work again. Sorry.

@dangquangminh
Copy link

how to remove $debug = true. I can fix this issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants