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

Error While Trying To Establish a Connection on SSL HTTPS #181

Open
jbalbert opened this issue Mar 22, 2019 · 15 comments
Open

Error While Trying To Establish a Connection on SSL HTTPS #181

jbalbert opened this issue Mar 22, 2019 · 15 comments

Comments

@jbalbert
Copy link

jbalbert commented Mar 22, 2019

Hello Good Day!

I have a problem establishing a connection server with my ssl certificate.

"An error occurred while trying to establish a connection to the server"

I have this code :

$this->client = new Client(new Version1X("https://www.sockettestserver.com:3000"));

And now I checked one of the tickets here like passing this $options:

$options = [
    'context' => [
        'ssl' => [
            'verify_peer' => false,
             'verify_peer_name' => false
        ]
    ]
];

$this->client = new Client(new Version1X("https://www.sockettestserver.com:3000",  $options));

But still I can't establish any connection.

If I am sending an http request it is working and it listens to port 3000 just fine.
But when I changed the connection to https I am getting that error.

Hope you can help me.

Thanks is advance.

@Taluu
Copy link
Contributor

Taluu commented Mar 22, 2019

As said in #179 (comment), please catch the exception and dump the getErrorMessage().

It should pinpoint you the error on why it couldn't connect your to the server.

BTW, IIUC, you are trying to make a ssl connection on a insecured port. Don't you have another port that is open for ssl ?

@jbalbert
Copy link
Author

jbalbert commented Mar 22, 2019

I am using port 443 for the ssl connection. Should I try using it instead of port 3000?

Is this also maybe one of the reason i cant make a connection?

@Taluu
Copy link
Contributor

Taluu commented Mar 22, 2019

Probably, give it a try. :}

@jbalbert
Copy link
Author

Okay Thanks. I am really new to sockets and ssl connections. I will give it try and give you a feedback.

@jbalbert
Copy link
Author

Hello @Taluu ,
I tried using port 443,
Here's what i got " This server does not support the websocket transport, aborting ",
Is this a problem on my node server or the elephant io itself?

Thank you

@Taluu
Copy link
Contributor

Taluu commented Mar 26, 2019

AFAIK, I think it's a problem on your node server. I think you're serving through http (not https) on the port 3000, and the port 443 is not listened by your node server but your http server (which can be different).

You also cannot (AFAIK) serve both secured and unsecured connections on the same port. So you should configure your node server to deliver a https connection on another port (or through the 3000).

@lorenzyannick
Copy link

I run into this issue, solved by :
https://www.php.net/manual/fr/function.stream-context-create.php#74795
and
https://www.php.net/manual/fr/context.http.php#121763

Must use context "http" not "ssl" in
wisembly/elephant.io/src/Engine/SocketIO/Version1X.php line 165

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

@Taluu
Copy link
Contributor

Taluu commented Jan 31, 2020

Care to make a PR ?

@lorenzyannick
Copy link

yes... I'll try later but with a proper code because because this lines is useless
$protocol = true === $this->url['secured'] ? 'http' : 'http';
same as : $protocol = 'http'

@lorenzyannick
Copy link

@Taluu
Copy link
Contributor

Taluu commented Jan 31, 2020

Yep just saw, that's why I deleted my comment. :}

I think there was an error at some point that needed the ssl context for ssl connections instead of https, but using the https:// protocol should be fine (with ssl context if you need some certificates).

@lorenzyannick
Copy link

Socket connect is ok (+ HEADERS working) in dev-master
But emit not working (write function ?)
Seems to be the same problem...
I fall back to 3.3.1 and change only Version1X.php line 165

I'll try to investigate later...

@daryn-k
Copy link

daryn-k commented Oct 3, 2021

@lorenzyannick any news in your investigation? I have the same error

@daryn-k
Copy link

daryn-k commented Oct 3, 2021

After passing $context parameter I fixed my situation.

    $options = [
      'context' => [
          'ssl' => [
              'verify_peer' => false,
               'verify_peer_name' => false
          ]
      ]
    ];
    
    $this->client = new Client(new Version1X("https://www.sockettestserver.com:3000",  $options));

@hugoalexmartins
Copy link

I'm having the same issue, the options you provide @daryn-k works.
But why suddenly this issue?

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

5 participants