Giter Club home page Giter Club logo

elephant.io's Introduction

Elephant.io

Build Status Latest Stable Version Total Downloads License

        ___     _,.--.,_         Elephant.io is a rough websocket client
      .-~   ~--"~-.   ._ "-.     written in PHP. Its goal is to ease the
     /      ./_    Y    "-. \    communications between your PHP Application and
    Y       :~     !         Y   a real-time server.
    lq p    |     /         .|
 _   \. .-, l    /          |j   Requires PHP 5.4 and openssl, licensed under
()\___) |/   \_/";          !    the MIT License.
 \._____.-~\  .  ~\.      ./
            Y_ Y_. "vr"~  T      Built-in Engines :
            (  (    |L    j      - Socket.io 2.x
            [nn[nn..][nn..]      - Socket.io 1.x
          ~~~~~~~~~~~~~~~~~~~    - Socket.io 0.x (courtesy of @kbu1564)

NOTICE

As this lib is not used anymore by the maintainers, the support has sadly been dropped. But rejoice, as a new repo is now maintained in its own organization : https://github.com/ElephantIO/elephant.io ! :)

Installation

We are suggesting you to use composer, with the following : php composer.phar require wisembly/elephant.io. For other ways, you can check the release page, or the git clone urls.

Documentation

The docs are not written yet, but you should check the example directory to get a basic knowledge on how this library is meant to work.

Special Thanks

Special thanks goes to Mark Karpeles who helped the project founder to understand the way websockets works.

elephant.io's People

Contributors

aquaminer avatar ardabeyazoglu avatar danielhusar avatar haykokoryun avatar kbu1564 avatar kcahir avatar lattwood avatar mshaverdo avatar musicstudionyc avatar nbz4live avatar neanton avatar nek- avatar padam87 avatar papattes avatar paulmhh avatar peter279k avatar seinopsys avatar taluu avatar teabreakninja avatar titanco avatar tot-ra avatar vincentdieltiens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elephant.io's Issues

Callback support in v3.0

Hello,
I'm trying to write simple client to test connection between different socket.io-powered apps. I would like to know how to implement callback mechanism in elephant.io v3.0, I wasn't able to find it in the code. I tried to use $client->read(), however I don't see how it could be used to intercept asynchronous messages as in v2.0 $elephant->callback() should do. What's more - using $client-read() in loop leads to program hanging on second iteration (data is read from socket PARTIALLY and then - program hangs when trying to read data again).

socket.io from 1.0 doesnot work with elephant

After a grueling solve the connection problem I ran into another problem with sending messages.It seems that socket.io js client sends some utf characters before sending data

With same input i got this -
socket.io js client for 1.0.6

socket.emit('init',{ 
        'hash' : 'Wl3xRMUOD3I2o2HcsROqJq5M66bVf0g4UQhhaZjjkl1aApiKSuTv3/EKiw6jTnvkBanrooyKwoSBVRqN3J7Xgg=='
    });

http://i.imgur.com/yH5DZ6Z.png

elephant.io for socket.io server 1.0.6

        $client->send(
                \ElephantIO\Client::TYPE_EVENT,
            null,
            null,
            json_encode(array('init' => array('hash' => 'Wl3xRMUOD3I2o2HcsROqJq5M66bVf0g4UQhhaZjjkl1aApiKSuTv3/EKiw6jTnvkBanrooyKwoSBVRqN3J7Xgg==')))
        );

http://i.imgur.com/G0KGljR.png

Callbacks

Hi!

when callbacks will work?

Thanks!

Default timeout on handshake

If elephant can't connect during the handshake, it may completely disrupt apache.

A solution is to find a correct timeout for the handshakeTimeout property, which can be set before calling init.

Currently, its default value is null... We should find a default value that is still acceptable, and that doesn't crash the server. Any idea ?

Read in init fails

My code is stuck in init() method. And the init() is through connect() stuck in read() which should return ::1, but it doesn't. Why? Let's have a look...

Initialy, buffer is empty. Through the connect() method, I got this headers through socket:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: AGFORzywpbZ3hZoB9+2DtiR/z60=

The, the read() kicks in, ant it's call $tmp = fread($this->fd, 4096); fetches the two bytes 0x81, 0x03 and then the desired string ::1. But the code of read() never returns it! It has some comparisons for 0xff and 0x00, but they are never satisfied.

So the read keaps listening, keeps getting messages, but always with 2 weird bytes (different, this time, not 0x81 and 0x03), until the server times out the socket because it's not responding to heartbeats (because php is stuck in read()'s while loop).

I added some debug outputs, so I could see what's in the buffer, ord values (in hex) of the current character and when new data are pulled to the buffer. Here is the output:

- debug -  HTTP/1.1 101 Switching Protocols

- debug -  Upgrade: websocket
- debug -  Connection: Upgrade
- debug -  Sec-WebSocket-Accept: AGFORzywpbZ3hZoB9+2DtiR/z60=
- debug -  Buffer: 
- debug -  Read ��1:: to buffer
- debug -  Buffer: ��1::
- debug -  81
- debug -  Buffer: �1::
- debug -  3
- debug -  Buffer: 1::
- debug -  31
- debug -  Buffer: ::
- debug -  3a
- debug -  Buffer: :
- debug -  Read ��2:: to buffer
- debug -  Buffer: :��2::
- debug -  3a
- debug -  Buffer: ��2::
- debug -  81
- debug -  Buffer: �2::
- debug -  3
- debug -  Buffer: 2::
- debug -  32
- debug -  Buffer: ::
- debug -  3a
- debug -  Buffer: :
- debug -  Read �,5:::{"name":"ringing","args":["voip1-ipex"]} to buffer
- debug -  Buffer: :�,5:::{"name":"ringing","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: �,5:::{"name":"ringing","args":["voip1-ipex"]}
- debug -  81
- debug -  Buffer: ,5:::{"name":"ringing","args":["voip1-ipex"]}
- debug -  2c
- debug -  Buffer: 5:::{"name":"ringing","args":["voip1-ipex"]}
- debug -  35
- debug -  Buffer: :::{"name":"ringing","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: ::{"name":"ringing","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: :{"name":"ringing","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: {"name":"ringing","args":["voip1-ipex"]}
- debug -  7b
- debug -  Buffer: "name":"ringing","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: name":"ringing","args":["voip1-ipex"]}
- debug -  6e
- debug -  Buffer: ame":"ringing","args":["voip1-ipex"]}
- debug -  61
- debug -  Buffer: me":"ringing","args":["voip1-ipex"]}
- debug -  6d
- debug -  Buffer: e":"ringing","args":["voip1-ipex"]}
- debug -  65
- debug -  Buffer: ":"ringing","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: :"ringing","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: "ringing","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: ringing","args":["voip1-ipex"]}
- debug -  72
- debug -  Buffer: inging","args":["voip1-ipex"]}
- debug -  69
- debug -  Buffer: nging","args":["voip1-ipex"]}
- debug -  6e
- debug -  Buffer: ging","args":["voip1-ipex"]}
- debug -  67
- debug -  Buffer: ing","args":["voip1-ipex"]}
- debug -  69
- debug -  Buffer: ng","args":["voip1-ipex"]}
- debug -  6e
- debug -  Buffer: g","args":["voip1-ipex"]}
- debug -  67
- debug -  Buffer: ","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: ,"args":["voip1-ipex"]}
- debug -  2c
- debug -  Buffer: "args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: args":["voip1-ipex"]}
- debug -  61
- debug -  Buffer: rgs":["voip1-ipex"]}
- debug -  72
- debug -  Buffer: gs":["voip1-ipex"]}
- debug -  67
- debug -  Buffer: s":["voip1-ipex"]}
- debug -  73
- debug -  Buffer: ":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: :["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: ["voip1-ipex"]}
- debug -  5b
- debug -  Buffer: "voip1-ipex"]}
- debug -  22
- debug -  Buffer: voip1-ipex"]}
- debug -  76
- debug -  Buffer: oip1-ipex"]}
- debug -  6f
- debug -  Buffer: ip1-ipex"]}
- debug -  69
- debug -  Buffer: p1-ipex"]}
- debug -  70
- debug -  Buffer: 1-ipex"]}
- debug -  31
- debug -  Buffer: -ipex"]}
- debug -  2d
- debug -  Buffer: ipex"]}
- debug -  69
- debug -  Buffer: pex"]}
- debug -  70
- debug -  Buffer: ex"]}
- debug -  65
- debug -  Buffer: x"]}
- debug -  78
- debug -  Buffer: "]}
- debug -  22
- debug -  Buffer: ]}
- debug -  5d
- debug -  Buffer: }
- debug -  Read �%5:::{"name":"busy","args":["vr1b74"]} to buffer
- debug -  Buffer: }�%5:::{"name":"busy","args":["vr1b74"]}
- debug -  7d
- debug -  Buffer: �%5:::{"name":"busy","args":["vr1b74"]}
- debug -  81
- debug -  Buffer: %5:::{"name":"busy","args":["vr1b74"]}
- debug -  25
- debug -  Buffer: 5:::{"name":"busy","args":["vr1b74"]}
- debug -  35
- debug -  Buffer: :::{"name":"busy","args":["vr1b74"]}
- debug -  3a
- debug -  Buffer: ::{"name":"busy","args":["vr1b74"]}
- debug -  3a
- debug -  Buffer: :{"name":"busy","args":["vr1b74"]}
- debug -  3a
- debug -  Buffer: {"name":"busy","args":["vr1b74"]}
- debug -  7b
- debug -  Buffer: "name":"busy","args":["vr1b74"]}
- debug -  22
- debug -  Buffer: name":"busy","args":["vr1b74"]}
- debug -  6e
- debug -  Buffer: ame":"busy","args":["vr1b74"]}
- debug -  61
- debug -  Buffer: me":"busy","args":["vr1b74"]}
- debug -  6d
- debug -  Buffer: e":"busy","args":["vr1b74"]}
- debug -  65
- debug -  Buffer: ":"busy","args":["vr1b74"]}
- debug -  22
- debug -  Buffer: :"busy","args":["vr1b74"]}
- debug -  3a
- debug -  Buffer: "busy","args":["vr1b74"]}
- debug -  22
- debug -  Buffer: busy","args":["vr1b74"]}
- debug -  62
- debug -  Buffer: usy","args":["vr1b74"]}
- debug -  75
- debug -  Buffer: sy","args":["vr1b74"]}
- debug -  73
- debug -  Buffer: y","args":["vr1b74"]}
- debug -  79
- debug -  Buffer: ","args":["vr1b74"]}
- debug -  22
- debug -  Buffer: ,"args":["vr1b74"]}
- debug -  2c
- debug -  Buffer: "args":["vr1b74"]}
- debug -  22
- debug -  Buffer: args":["vr1b74"]}
- debug -  61
- debug -  Buffer: rgs":["vr1b74"]}
- debug -  72
- debug -  Buffer: gs":["vr1b74"]}
- debug -  67
- debug -  Buffer: s":["vr1b74"]}
- debug -  73
- debug -  Buffer: ":["vr1b74"]}
- debug -  22
- debug -  Buffer: :["vr1b74"]}
- debug -  3a
- debug -  Buffer: ["vr1b74"]}
- debug -  5b
- debug -  Buffer: "vr1b74"]}
- debug -  22
- debug -  Buffer: vr1b74"]}
- debug -  76
- debug -  Buffer: r1b74"]}
- debug -  72
- debug -  Buffer: 1b74"]}
- debug -  31
- debug -  Buffer: b74"]}
- debug -  62
- debug -  Buffer: 74"]}
- debug -  37
- debug -  Buffer: 4"]}
- debug -  34
- debug -  Buffer: "]}
- debug -  22
- debug -  Buffer: ]}
- debug -  5d
- debug -  Buffer: }
- debug -  Read �)5:::{"name":"busy","args":["voip1-ipex"]} to buffer
- debug -  Buffer: }�)5:::{"name":"busy","args":["voip1-ipex"]}
- debug -  7d
- debug -  Buffer: �)5:::{"name":"busy","args":["voip1-ipex"]}
- debug -  81
- debug -  Buffer: )5:::{"name":"busy","args":["voip1-ipex"]}
- debug -  29
- debug -  Buffer: 5:::{"name":"busy","args":["voip1-ipex"]}
- debug -  35
- debug -  Buffer: :::{"name":"busy","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: ::{"name":"busy","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: :{"name":"busy","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: {"name":"busy","args":["voip1-ipex"]}
- debug -  7b
- debug -  Buffer: "name":"busy","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: name":"busy","args":["voip1-ipex"]}
- debug -  6e
- debug -  Buffer: ame":"busy","args":["voip1-ipex"]}
- debug -  61
- debug -  Buffer: me":"busy","args":["voip1-ipex"]}
- debug -  6d
- debug -  Buffer: e":"busy","args":["voip1-ipex"]}
- debug -  65
- debug -  Buffer: ":"busy","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: :"busy","args":["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: "busy","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: busy","args":["voip1-ipex"]}
- debug -  62
- debug -  Buffer: usy","args":["voip1-ipex"]}
- debug -  75
- debug -  Buffer: sy","args":["voip1-ipex"]}
- debug -  73
- debug -  Buffer: y","args":["voip1-ipex"]}
- debug -  79
- debug -  Buffer: ","args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: ,"args":["voip1-ipex"]}
- debug -  2c
- debug -  Buffer: "args":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: args":["voip1-ipex"]}
- debug -  61
- debug -  Buffer: rgs":["voip1-ipex"]}
- debug -  72
- debug -  Buffer: gs":["voip1-ipex"]}
- debug -  67
- debug -  Buffer: s":["voip1-ipex"]}
- debug -  73
- debug -  Buffer: ":["voip1-ipex"]}
- debug -  22
- debug -  Buffer: :["voip1-ipex"]}
- debug -  3a
- debug -  Buffer: ["voip1-ipex"]}
- debug -  5b
- debug -  Buffer: "voip1-ipex"]}
- debug -  22
- debug -  Buffer: voip1-ipex"]}
- debug -  76
- debug -  Buffer: oip1-ipex"]}
- debug -  6f
- debug -  Buffer: ip1-ipex"]}
- debug -  69
- debug -  Buffer: p1-ipex"]}
- debug -  70
- debug -  Buffer: 1-ipex"]}
- debug -  31
- debug -  Buffer: -ipex"]}
- debug -  2d
- debug -  Buffer: ipex"]}
- debug -  69
- debug -  Buffer: pex"]}
- debug -  70
- debug -  Buffer: ex"]}
- debug -  65
- debug -  Buffer: x"]}
- debug -  78
- debug -  Buffer: "]}
- debug -  22
- debug -  Buffer: ]}
- debug -  5d
- debug -  Buffer: }

Elephant.io Error: Undefined offset: 3 in /var/www/lib/ElephantIO/Client.php on line 327

I am using ubuntu 12.04.4 , I had got an error Undefined offset: 3 in /var/www/lib/ElephantIO/Client.php on line 327 when emtting a request to the node.js using Elephant.io Which lead to an exception

Uncaught exception 'Exception' with message 'This socket.io server do not support websocket protocol. Terminating connection...

Here is my code

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

    $elephant = new ElephantIOClient('http://localhost:9000', 'socket.io', 1, false, true, true);
    $elephant->init();
    $elephant->emit('message','enroll');
    $elephant->close();

Note: I have this above code working in Windows Os

Please help me to solve this at the earliest.

Client receives two messages even if only one was sent.

When I send a message/event from PHP, my client receives two messages instead of one.

PHP code:
$s = $elephant->send(
ElephantIO\Client::TYPE_EVENT,
null,
null,
json_encode(array('name' => 'event_name', 'args' => array('...')))
);

Node.js code:
socket.on ('event_name', function (data) {
socket.broadcast.emit('another_event', data.msg, data.id_booking);
console.log("Event triggered "+data.msg);
});

Client code:
socket.on('another_event', function (msg, id_booking) {
alert("Another event triggered!");
});

On the client I get two alerts instead of just one. What could be the problem?

I mention that I transfer other messages too but without elephant.io and everything works ok. Just this example has this issue, that's why I suspect it's something about elephant.io

Thanks in advance,
Stef

Error: read ECONNRESET

I am using elephant.io to emit some status messages to a node server .
After the user clicks a button, some date is written to a database (PHP/Mysql), elephant.io emits a message to the node server and the user is REDIRECTED to an other page.

I am using socket.io on the node server.
When elephant.io emits the message the following info occured in the log:

info  - socket error Error: read ECONNRESET
 at errnoException (net.js:878:11)
 at TCP.onread (net.js:539:19)
info  - transport end (close timeout)

Maybe the redirect has something to do with the error?
In general the code works but after some hours the node server eats up 100% CPU, and perhaps this error has something to do with it (people where not properly disconnected and such).

How can I get rid of this message? Or how can I catch it? I am experimenting with error callbacks for a while but simply don't get it. Any help will be much appreciated.

How to set handshake query for 3.0?

Pre 3.0 I was using this to set the handshake query:

$elephant->setHandshakeQuery( array( "query" => "token=".$token->token ) );

How do I do this in 3.0?

Uncaught exception 'Exception' with message 'couldn't connect to host'

i get following error when i run

http://192.168.2.5/chat/phpchat/elephant.io-master/example/client.php

Error is below:
Uncaught exception 'Exception' with message 'couldn't connect to host' in /Applications/XAMPP/xamppfiles/htdocs/chat/phpchat/elephant.io-master/lib/ElephantIO/Client.php:255 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/chat/phpchat/elephant.io-master/lib/ElephantIO/Client.php(52): ElephantIO\Client->handshake() #1 /Applications/XAMPP/xamppfiles/htdocs/chat/phpchat/elephant.io-master/example/client.php(8): ElephantIO\Client->init() #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/chat/phpchat/elephant.io-master/lib/ElephantIO/Client.php on line 255

Read function reads less that payload length on big frames.

Hi, I've been started testing the library to see if it fits my needs and I've found that when socket.io returns a long frame (> 16Kb in my system), the read method does not reads the full frame data. I've written a fix for this for the method client->read. Hope that it helps someone.

public function read() {
    // Ignore first byte, I hope Socket.io does not send fragmented frames, so we don't have to deal with FIN bit.
    // There are also reserved bit's which are 0 in socket.io, and opcode, which is always "text frame" in Socket.io

    $header  = fread($this->fd, 1);
    //$finFlag = $header & bindec('10000000') ? true : false;
    //$opcode  = $header & bindec('00001111');

    // There is also masking bit, as MSB, but it's 0 in current Socket.io
    $payload_len = ord(fread($this->fd, 1));

    switch ($payload_len) {
        case 126:
            $payload_len = unpack("n", fread($this->fd, 2));
            $payload_len = $payload_len[1];
            break;
        case 127:
            $this->stdout('error', "Next 8 bytes are 64bit uint payload length, not yet implemented, since PHP can't handle 64bit longs!");
            break;
    }

    // Reads the socket until full data is read
    //$payload = fread($this->fd, $payload_len); // Does not works if packet size > 16Kb
    $payload = '';
    $read    = 0;
    while( $read < $payload_len && ( $buf = fread( $this->fd, $payload_len - $read ) ) )
    {
        $read    += strlen($buf);
        $payload .= $buf;
    }

    $this->stdout('debug', 'Received ' . $payload);

    return $payload;
}

disconnect after some time

Hi,

i'm doing a long running import and send progress percentage to the browser. when the import reaches around 12% which is around 50s, the elephant client gets disconnected. There's no error, no message, just socket.io shows it was disconnected. the client is still sending messages happily, but they don't propagate to the browser.

i was pushing the progress every 1% of the import, then i doubled the frequency to 0.5% but everytime the import reached 12% it got disconnected.

is there a way how to catch this and reconnect?

When many times payload send to data, it is not sending to data sometimes.

The issue about regard of this problem is #68.

I was catched exception about this problem. This problem of @ve3 will occur to source like next.

$client = new Client(new Version1X('http://localhost:1337'));
$client->initialize();
for ($i = 0; $i < 10; $i++) {
    $emit_result = $client->emit('broadcast', ['sayhi' => 'Hello Hi :: ' .date('Y-m-d H:i:s'),
                                               'index' => $i]);
}
$client->close();

When the code of before is testing, Send to 10 times but data send about 6-9 times.
@Taluu I think that this problem should check about version 1.x and 0.x of elephant.io.

execute code about before:
pc2

The Results of all test cases was executed about code to same.

Automatically determine which version of Socket.io is used

The Version 0.X and 1.X of Socket.io is get the version of /socket.io/socket.io.js like next.

public function getVersion()
{
    // get socket.io version
    $url = 'http://' . $this->url['host'] . ':' . $this->url['port'];
    if (true === $this->url['secured']) {
        $url = 'https://' . $this->url['host'] . ':' . $this->url['port'];
    }

    $url .= '/socket.io/socket.io.js';
    // need to ini_set('allow_url_fopen', 'On');
    $socketio = file_get_contents($url);
    preg_match_all('/io\.version = [\'\"]([0-9\.]+)[\'\"];/', $socketio, $match);

    if (isset($match[1]) === false)
        return '1.x.x';

    return $match[1][0];
}

If elephant.io/src/Client.php of refacto-3.0 is used like next, i want to listen for your think.

// The Client class was used getVersion() into the Client::__construct.
$client = new Client('http://localhost:9001');

$client->initialize();
$client->emit('broadcast', ['foo' => 'bar']);
$client->close();

Add custom variables in handshake headers

Hi
Excellent work. Is there a way to add some custom headers in the variable of the handshake when connecting?
For example, on the js client I do:
socket = io.connect(adress, {query: 'token='+token});
So on server I have:
io.set('authorization', function(handshake, accept){
var token = handshake.query.token;
});

How can I add a custom variable in header in Elephant.io when making connection?

Autoloader

Greetings
you used in the project autoloader from composer, what if the project is not used and will not be used composer? how to use the autoloader?

Join and leave rooms

Hi
I would like to know how to join and leave rooms with ElephantIO API ?
Here is what I want to do :

  • I have a javascript client (in a HTML page) which uses socket.io javascript connection to a socket.io (nodejs) server
  • I have a PHP script which connect to this same socket.io server in order to send a message to my javascript client
    So I thought that rooms were the solution but I don't how to use them with ElephantIO
    Your help will be very appreciated !
    Best regards.

Emit event with json data

When i send a event with json data, the data is sent as a string, this not happen using the socketio-client

screenshot

In the image the first message is sent using elephantio and the second one was sent using socketio-client

Default port is not used

If there is no port specified, the default port (80) is ignored and replaced with null.

Client on line 335: $this->serverPort = isset($url['port']) ? $url['port'] : null;

change to

$this->serverPort = isset($url['port']) ? $url['port'] : $this->serverPort;

or

if (isset($url['port'])) {
    $this->serverPort = $url['port'];
}

Differenciate the timeout option

Currently, there is only one "timeout" option. I think it would be better to differenciate between the timeout made at the connection (during the handshake per example) and the one during the connection (set on the stream)

A "little" rewrite

Hi all,

I've done a "little" refactoring of elephant.io. Due to the number of changes, I don't think it's a good thing to pull request without your validation.
I push it on a branch of my fork : https://github.com/lalmat/elephant.io/tree/refactoring

I've tried to follow the Socket.IO 1.0.x philosophy and I've provided a little example to show you how it works.

Due to my lack of free time, I haven't be able to code the tests classes and manage the timeout on the handshake yet... I hope to have the time to do it soon, but maybe you can already try this refactoring and give me your feedback

Thanks.

Namespace Socket.io

How connect elephant.io to namespace of socket.io ?

i trying with this code:

$elephant = new ElephantIOClient('host:port/xxx' 'socket.io',1, false, false, false);

this generate error in line 231 of Client.php

elephant.io can connect namespace?

Documentation

Hello all,

Thanks for this great tool. But developers need documentation for this. I have to solve some problems on our app and I try to use elephant.io first time but I don't know where to start. Can you help me? I just need some example how to setting up and how to combine my existing methods with e.io.

Thanks in advance!

Status of ssl connect in current version

I just upgraded versions of socket.io and elephant.io to the current versions and ported on my code to do things correctly. Everything works fine in http in development, but I have to use https in production. With https, socket.io works 100% fine js client / server, but elephant.io will not connect. Are there any current issues with ssl stream connects? The $host path looks correct going into the connect, so I'm wondering if any additional context info is missing. This all worked really well the old way (when init() existed.) ;-)

Socket.IO ip address

When i connect through elephant.IO to Socket.IO 1.x i cant find ip address of client:

io.use(function(socket, next){
    var ip = socket.request.connection.remoteAddress;
    console.log(socket.request.connection.destroyed); // true
    console.log(ip); // undefined
});

ssl in version 1.x

I had an error establishing connection with ssl in version 1.x
I changed 'ssl' for 'https' in Version1X.php in method handshake() and it's working.

PHPStorm support & phpdoc standards

Hello guys !

Since PHPStorm follow PHPDoc standards to support it and you doesn't, the support is broken.

The solution to fix it is just to add a \ before classes namespaces in the PHPDoc.

(I will try to make a PR asap if you like the idea)

How does receiver works?

I'm sorry i know this is not real issue but i'm stuck with it.
I'm already look into example here. https://github.com/Wisembly/elephant.io/tree/master/example/socket.io/1.x/receiver
And i don't know how to make receiver works.

Once i push data to socket.
The js in client page received the message and if I reload that page the message gone.
So, i am really do not know how to read it via elephant.io.
What i have to do more?

This is my code.

$client = new \ElephantIO\Client(new \ElephantIO\Engine\SocketIO\Version1X('http://localhost:1337'));

$client->initialize();
$r = $client->read();
$client->close();

var_dump($r);

Avoid reading payload twice

When reading from the socket, there is a first reading to extract the full payload from the stream, and then there is a second reading to actually interpret the extracted payload in the Decoder.

I think that factorizing these actions could be a pretty good enhancement ; a solution would be to include the stream reading directly into the decoder, but I'm not a huge fan, as the decoder should only decode the full payload (and that's it), without any coupling.

undefined variables c and tmp in ElephantIoClient::generateKey()

on init() I'll get the following php errors:

ERROR - 2013-04-21 10:42:37 --> Severity: Notice  --> Undefined variable: c D:\xampp\htdocs\slaw\application\libraries\ElephantIO\ElephantIoClient.php 209
ERROR - 2013-04-21 10:42:37 --> Severity: Notice  --> Undefined variable: tmp D:\xampp\htdocs\slaw\application\libraries\ElephantIO\ElephantIoClient.php 210

defined variables as follows, but I don't know, if this is going to break something:

$c = 0;
$tmp = '';

Rooms

Looking at the code, i guess rooms are not supported yet ?

Read function

Hi
I am having problems when reading a message from the server. My server is based on netty-socketio and the way I send messages to a client is: this.client.sendEvent("serverMessage",message);
The messages are encrypted. As you can see netty-socketio is orientated to events.
The issue I am experiencing is that for example if I send "75559" I read 42["serverMessage","7 .
I am not reading the entire message and also I am reading the event name I use to send messages from netty-socketio to elephant.io.
Do you know why I am not reading the entire message?
Thanks

Worked in the first but

Hey;

It was working in the first with your example but now the php file saying

|Fatal error: Uncaught exception 'Exception' with message 'couldn't connect to host' |

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

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?

Random exception: Socket.io did not send connect response. Aborting

Hello. Great work. Thank you for sharing.

I'm experiencing random exceptions in emit calls. All browser connections was stable. Don't think it was a Node.JS or Socket.io client issue.

I'm using Node.js 10.26 and Socket.io 0.9.16.
I'm using sync disconnect on unload option enabled in Socket.io client.
All transports are enable in Node.js server: websocket, flashsocket, htmlfile, xhr-polling and jsonp-polling.

Any clue about this?

Best regards.

Slow event emission (~10s)

I've downgraded to socket.io v0.9.x because of handshake issues with v1.0.x.

In my simple test (local server) I'm sending a very small JSON string to my nodejs server. The overall process it taking up to 10-15s which appear to be very long.

handshake: ~7s
connect: ~7s
send event: ~1s

Is there any way to speed up this?

Unexpected Response. Expected HTTP/1.1 101 got 1. Aborting...

i run a node server listening to 8443.

it can work using
$el=new Elephant("https://w.cc:8443", 'socket.io', 1, false, false, false);

it occured error when i using
$el=new Elephant("https://w.cc", 'socket.io', 1, false, false, false);

the error message is Unexpected Response. Expected HTTP/1.1 101 got 1. Aborting...

i got the returned message is HTTP/1.1 400 Bad Request

i've set reverse proxy in nginx.conf,in browser the code
io.connect("https://w.cc") can run.

Could not connect to server when node.js/socket.io not start. Please make is connected to check.

I have this code to connect socket.io via elephant.io

$client = new \ElephantIO\Client(new \ElephantIO\Engine\SocketIO\Version1X('http://' . $cfg_socket['socket_host']['value'] . ':' . $cfg_socket['socket_port']['value']));
$client->initialize();
$client->emit('customer', $socket_io_data);
$client->close();
unset($client, $socket_io_data);

When i started node.js/socket.io it works properly. But when i did not start the node.js/socket.io it throw an error even if i use @Suppress cannot stop that error.

Please make something like isConnected() method to check before initialize() throw the error.

Callbacks

Hi!

when callbacks will work?

Thanks!

Elephant.io Exception: This socket.io server do not support websocket protocol. Terminating connection...

Hello I am using ubuntu 12.04 and i installed nodejs and socket.io successfully. Here i am putting some scripts for you more understanding please anyone give me positive reply.

Here First thing run server.js on nodejs engine
When run client.html file it works perfectly because it sends message successfully to server.js and also server returns message successfully.
But when run publisher.php it will stops after this exception like:
"This socket.io server do not support websocket protocol. Terminating connection..."
Now I don't understand where i am mistaken. plz give some solution.
One more thing is this every code working properly on windows local system.

  1. server.js (running on nodejs server by using 'node server.js' command)
    var server = require('http').Server();
    var io = require('socket.io')(server);
    io.on('connection', function(socket){
    console.log('user connected');
    socket.on('action', function(data){
    console.log('Action :'+data);
    socket.emit('Reply','Reply :Crow is Croun and Frog is Droun');
    });
    socket.on('disconnect', function(){});
    });
    server.listen(3000);

  2. publisher.php (This is php file and using Elephant.io library)

init(); $elephant->emit('action', 'foo'); $elephant->close(); echo 'tryin to send `foo` to the event called action'; 3) Client.html <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> ``` <script src="../nodejs/node_modules/socket.io/node_modules/socket.io-client/socket.io.js"></script> <script> $(function(){ window.MY_Socket = { // Instantiate the Socket.IO client and connect to the server socket : io.connect('http://localhost:3000'), // Set up the initial event handlers for the Socket.IO client bindEvents : function() { this.socket.on('Reply',MY_Socket.startupMessage); MY_Socket.socket.emit('action','The world is round, there is no up or down.'); }, // This just indicates that a Socket.IO connection has begun. startupMessage : function(data) { console.log(data); } } // end window.MY_Socket // Start it up! MY_Socket.bindEvents(); }); </script> ```

socket.io from v1.0.x return error on handshake

When enabling curl verbose during the handshake I can see that socket.io is returning an HTTP 400:

* Adding handle: conn: 0x7fd781809000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 1 (0x7fd781809000) send_pipe: 1, recv_pipe: 0
* About to connect() to acme.local port 3700 (#1)
*   Trying 127.0.0.1...
* Connected to acme.local (127.0.0.1) port 3700 (#1)
> GET /socket.io/1 HTTP/1.1
Host: acme.local:3700
Accept: */*

< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Date: Mon, 02 Jun 2014 01:39:33 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
* Connection #1 to host acme.local left intact

Directly hitting the nodejs server in the browser:
http://acme.local:3700/socket.io/1

{
    code: 0,
    message: "Transport unknown"
}

I think it's missing some parameters in the handshake query. I'm using the master branch. I'll try to switch to 2.0.x to see if it change something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.