0

I have a websocket chat on my website and I recently added SSL certificate to my website. When I open my website with http, chat works. When I open it with https it's not working. I am using javascript as client for my chat with ws:// protocol. I changed that protocol to wss:// because of SSL encryption on my page, but it won't work that way. Here's part of my PHP server code that creates the socket:

$host = 'localhost'; 
$port = '9000'; 
$null = NULL;

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);

socket_bind($socket, 0, $port);

socket_listen($socket);

$clients = array($socket);
johnnyasda2
  • 11
  • 1
  • 2
  • Seems you are missing ssl serteficate configuration for your wss, you can check first answer here: http://stackoverflow.com/questions/6969316/securing-websockets there is written `You will need to have a signed SSL certificate configured with your websocket server, but that's pretty much required anyways.` – Armen Jan 27 '16 at 08:03
  • 1
    Yes, I am aware of that, but how do I add my certificate to a `php socket`? – johnnyasda2 Jan 27 '16 at 08:08

1 Answers1

0

how do you add a certificate to a php socket?

using a different function call.

http://php.net/manual/en/function.stream-socket-client.php

and setting the correct socket options

http://php.net/manual/en/context.ssl.php

Paul Dunlop
  • 327
  • 1
  • 5
  • 2
    Can you post a sample code please? And shouldn't I use `stream_socket_server` instead of `stream_socket_client`? – johnnyasda2 Jan 27 '16 at 09:54