elephant.io icon indicating copy to clipboard operation
elephant.io copied to clipboard

Cannot be establish the connection with server

Open hugohenrique opened this issue 6 years ago • 21 comments

I'm not able to establish a connection to the server using this php client. With the javascript client I usually get it.

An error occurred while trying to establish a connection to the server relates #163 #161 #160

I've been using port 3000 on the server.

hugohenrique avatar Nov 20 '17 18:11 hugohenrique

Do you have more information ? The exception should be more verbose now.

Taluu avatar Nov 20 '17 19:11 Taluu

screen shot 2017-11-20 at 16 38 45 screen shot 2017-11-20 at 16 39 41 screen shot 2017-11-20 at 16 39 49 screen shot 2017-11-20 at 16 39 58 ping @Taluu

hugohenrique avatar Nov 20 '17 19:11 hugohenrique

I'm suspecting you should use the Version2X instead of Version1X (as it is told in the tickets you linked). Anyway, more information should be available in the getErrorMessage method of the ServerConnectionFailureException class, which is thrown on this error.

Taluu avatar Nov 20 '17 19:11 Taluu

I'm already using the Version2X class and now I've added a try/catch and the getErrorMessage method is returning null.

hugohenrique avatar Nov 20 '17 19:11 hugohenrique

Which version are you using ? Because the line 190 is not the one throwing the exception on latest tag and master...

Otherwise, could you add a sort of dump of the $error variable just before the exception is thrown ? Thanks.

Taluu avatar Nov 20 '17 19:11 Taluu

I'm using the 3.3.1 and I will try with dev-master version

hugohenrique avatar Nov 20 '17 20:11 hugohenrique

Removing the @ in @file_get_contents... line 177 Version1X.php I received this warning:

Warning: file_get_contents(http://127.0.0.1:3000/socket.io/?use_b64=0&EIO=3&transport=polling): failed to open stream: Connection refused

hugohenrique avatar Nov 20 '17 20:11 hugohenrique

Try to access http://127.0.0.1:3000/socket.io/?use_b64=0&EIO=3&transport=polling then http://127.0.0.1:3000/socket.io/?use_b64=0&EIO=3&transport=polling ? In your given uri (in the construct), what is the value of the given url ?

Taluu avatar Nov 20 '17 20:11 Taluu

(I think it comes from elephant.io, I'll try to look up if when I'll be getting some time)

Taluu avatar Nov 20 '17 21:11 Taluu

The error was not in the lib but in my network. Sorry and thanks for your attention. @Taluu.

hugohenrique avatar Nov 20 '17 21:11 hugohenrique

Np. But reopening as it brought an error to my attention. :)

Taluu avatar Nov 20 '17 21:11 Taluu

I had the same issues. There is more then one pitfall btw. In my case docker container had a wrong port alignment. So: check ports in case of docker (e.g https://server_node:8443) But also a self-asigned tls/ssl can couse trouble. Use this workaround $context = [ 'http' => [ 'method' => 'GET' ], 'ssl' => [ 'verify_peer' => true, 'allow_self_signed'=> true ] ]; @ stream_context_create()

But also your php.ini may need some more flags. Make sure allow_url_fopen is On

Surfable avatar Jun 14 '18 17:06 Surfable

This is usually caused by connection errors that gets eaten by the @file_get_contents line. The best would be to handle them instead.

SeinopSys avatar Nov 19 '18 10:11 SeinopSys

I am getting the same issues. It caused after I switched from http to https @Taluu

nidheesh1994 avatar Jun 13 '19 10:06 nidheesh1994

try https://github.com/Wisembly/elephant.io/issues/181#issuecomment-580669128

lorenzyannick avatar Jan 31 '20 10:01 lorenzyannick

may help you

comment lines 175 ~ 185 in /Engine/SocketIO/Version1X.php

then write this code

$protocol = true === $this->url['secured'] ? 'ssl' : 'http';

if(isset($this->context[$protocol])){
    $context = $this->context;
    $context['http']=$context[$protocol];
    @unset($context['ssl']);
}
$context['http'] = $context['http'] ?? [];

if (isset($this->options['headers'])) {
    $headers = $context[$protocol]['header'] ?? [];
    $context['http']['header'] = array_merge($headers, $this->options['headers']);
}
if (isset($this->options['ssl'])) {
    $ssl = $context[$protocol]['ssl'] ?? [];
    $context['ssl'] = array_merge($ssl, $this->options['ssl']);
}

bh013 avatar Nov 10 '20 13:11 bh013

may help you

comment lines 164 ~ 174 in /Engine/SocketIO/Version1X.php

then write this code

$protocol = true === $this->url['secured'] ? 'ssl' : 'http';

if(isset($this->context[$protocol])){
    $context = $this->context;
    $context['http']=$context[$protocol];
    @unset($context['ssl']);
}
$context['http'] = $context['http'] ?? [];

if (isset($this->options['headers'])) {
    $headers = $context[$protocol]['header'] ?? [];
    $context['http']['header'] = array_merge($headers, $this->options['headers']);
}
if (isset($this->options['ssl'])) {
    $ssl = $context[$protocol]['ssl'] ?? [];
    $context['ssl'] = array_merge($ssl, $this->options['ssl']);
}

I am using this code. How can I solve the problem?

$client = new Client(new Version2X('https://xxxxx:6001', ['context' => ['ssl' => [ 'verify_peer_name' =>false, 'verify_peer' => false ] ]] ));

seyitahmettanriver avatar Dec 02 '20 23:12 seyitahmettanriver

https://stackoverflow.com/a/66090819/4690409

berkturk avatar Dec 23 '21 21:12 berkturk

What are u even talking about

On Thu, Dec 23, 2021, 2:14 PM burak berktürk @.***> wrote:

https://stackoverflow.com/a/66090819/4690409

— Reply to this email directly, view it on GitHub https://github.com/Wisembly/elephant.io/issues/165#issuecomment-1000526176, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADIIPOSKDDXPJWAVTHXMBHDUSOGKPANCNFSM4EESWODA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

andyfink avatar Dec 26 '21 07:12 andyfink

I am also facing same issue, I am not sure but I find out that if I connect to server using socket version ^3.0.0 than I am getting connection error but when I am using version ^2.0.0 It is establish connection successfully.

Is there any other library I can use for socket connection with version 3?

HirenViradia avatar May 02 '22 11:05 HirenViradia

Since this package is largely unmaintained as far as I'm aware I've also stopped using it in my own app, and have not found a suitable replacement since.

SeinopSys avatar May 02 '22 11:05 SeinopSys