Giter Club home page Giter Club logo

Comments (7)

kbu1564 avatar kbu1564 commented on July 19, 2024

@ve3 We can catch to exception about server connection failure.
I think that isConnect was not needed.

When you used code like next, you would catch to exception to server connection failure.

<?php
use ElephantIO\Client,
    ElephantIO\Engine\SocketIO\Version1X,
    ElephantIO\Exception\ServerConnectionFailureException;

require __DIR__ . '/../../../../vendor/autoload.php';

$client = new Client(new Version1X('http://localhost:1337'));

try
{
    $client->initialize();
    $client->emit('broadcast', ['foo' => 'bar']);
    $client->close();
}
catch (ServerConnectionFailureException $e)
{
    echo 'Server Connection Failure!!';
}

from elephant.io.

ve3 avatar ve3 commented on July 19, 2024

@kbu1564 No, I cannot use try catch.
I was tried this before but the Elephant.IO throw the error before it pass to catch the error. That's why i need isConnected() method.

from elephant.io.

kbu1564 avatar kbu1564 commented on July 19, 2024

@ve3 I think that you were not used to namespace of ElephantIO\Exception\ServerConnectionFailureException.

If you were not used about namespace, you can modify like next. :)

<?php
use ElephantIO\Exception\ServerConnectionFailureException;

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

try
{
    $client->initialize();
    $client->emit('broadcast', ['foo' => 'bar']);
    $client->close();
}
catch (ServerConnectionFailureException $e)
{
    echo 'Server Connection Failure!!';
}

from elephant.io.

ve3 avatar ve3 commented on July 19, 2024

I was tried that exactly you said and i was tried more than twice but It did not work.
"An error occurred while trying to establish a connection to the server"
This error was throw before it can catch

Please try it yourself first.

from elephant.io.

ve3 avatar ve3 commented on July 19, 2024

Quote:
ElephantIO\Exception\ServerConnectionFailureException [ Error ]:
An error occurred while trying to establish a connection to the server
((file location:)) wisembly/elephant.io/src/Engine/SocketIO/Version1X.php @ line 144

144 throw new ServerConnectionFailureException;

You cannot prevent thrown error (http://stackoverflow.com/questions/8835004/php-throw-exception-is-caught-but-the-error-message-still-appear).

I just want to use socket.io as optional, that's why when it is not connected I want it just pass without throwing the error.
And that's why i needs isConnected. There is no other way to do this except making something to check the connection.

from elephant.io.

Taluu avatar Taluu commented on July 19, 2024

As @kbu1564 said, this exception occurs only on the handshake... which is catchable. When using write, a check is made to check if the connection is made, and does nothing it the connection is not active. The try catch should do the trick (we're using it just fine here at Wisembly, with the dialog being optionnal)

I don't really see the point for a isConnected method...

from elephant.io.

ve3 avatar ve3 commented on July 19, 2024

Ok, I found the point of this problem now, thank you all.
@Taluu @kbu1564

from elephant.io.

Related Issues (20)

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.