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

Cannot be establish the connection with server #165

Open
hugohenrique opened this issue Nov 20, 2017 · 21 comments
Open

Cannot be establish the connection with server #165

hugohenrique opened this issue Nov 20, 2017 · 21 comments

Comments

@hugohenrique
Copy link

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.

@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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

@Taluu Taluu added the support label Nov 20, 2017
@hugohenrique
Copy link
Author

hugohenrique commented Nov 20, 2017

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

@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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.

@hugohenrique
Copy link
Author

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

@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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.

@hugohenrique
Copy link
Author

hugohenrique commented Nov 20, 2017

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

@hugohenrique
Copy link
Author

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

@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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 Taluu added the bug label Nov 20, 2017
@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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

@hugohenrique
Copy link
Author

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

@Taluu
Copy link
Contributor

Taluu commented Nov 20, 2017

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

@Taluu Taluu reopened this Nov 20, 2017
@Surfable
Copy link

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

@SeinopSys
Copy link
Contributor

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

@nidheesh1994
Copy link

nidheesh1994 commented Jun 13, 2019

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

@lorenzyannick
Copy link

try #181 (comment)

@bh013
Copy link

bh013 commented Nov 10, 2020

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']);
}

@seyitahmettanriver
Copy link

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
]
]]
));

@berkturk
Copy link

@andyfink
Copy link

andyfink commented Dec 26, 2021 via email

@HirenViradia
Copy link

HirenViradia commented May 2, 2022

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?

@SeinopSys
Copy link
Contributor

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.

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

No branches or pull requests