1

I cannot establish a connection with the PHP WebSocket server, client closes it with code 1006 "Abnormal Closure".

Client code:

var host = "ws://example.com:1234/test/server.php";

Server Code (test/server.php):

$host = 'tcp://example.com:1234';

  1. I tried different WebSocket PHP libraries.
  2. I tried different hosts ("127.0.0.1", "0.0.0.0", "example.com").
  3. sudo netstat -plnt shows that port is listened.
  4. Appropriate TCP port is opened (firewall settings in ISPConfig 3).

But connection still not working. Any ideas?

Thank you in advance.

topright gamedev
  • 2,617
  • 7
  • 35
  • 53
  • Which PHP WebSocket libraries have you tested? – Zander Rootman May 05 '14 at 12:43
  • 1. https://github.com/morozovsk/websocket 2. https://github.com/esromneb/phpwebsocket 3. https://github.com/ghedipunk/PHP-Websockets – topright gamedev May 05 '14 at 12:47
  • 1
    Going to take a look at those libraries quick.. In the meanwhile, think you might find it helpful to read this SO post: http://stackoverflow.com/questions/19304157/getting-the-reason-why-websockets-closed – Zander Rootman May 05 '14 at 12:48
  • 3
    Also, I don't mean to pour you down with things to read up on, but I recently started using sockets (with PHP) myself, and this library (http://socketo.me/) had good documentation, and a nice community. I'd recommend you take a look at it. – Zander Rootman May 05 '14 at 12:52
  • Thank you very much! I've read that SO post, it is very detailed, but not concrete enough to solve an issue. – topright gamedev May 05 '14 at 12:55
  • Ratchet has good reputation, but has many dependencies and requires Composer to be installed. I would like to use another minimalistic solution. – topright gamedev May 05 '14 at 12:57
  • Yeah I can completely understand that, but PHP was never designed with Web Sockets in mind, and when you want to force it to have, I'd highly recommend you use something that has a few dependencies, but ensures more stability. And composer is as easy to use as GIT :) – Zander Rootman May 05 '14 at 13:04
  • What if Ratchet will not work after all, too? :) May be it is server configuration issue? – topright gamedev May 05 '14 at 13:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52038/discussion-between-user3345621-and-topright-gamedev) – Zander Rootman May 05 '14 at 13:24
  • Ok! Thank you again, you are very responsive! I've answered there. – topright gamedev May 05 '14 at 13:43
  • Actually, it's just not enough information to be helpful other than by wild guessing. Websockets definitively work… Does it already abort upon connection or shortly later? Does your PHP script abort? – bwoebi May 08 '14 at 16:16
  • @bwoebi, server returns 0 bytes. PHP script doesn't receive a request, so script cannot abort it. – topright gamedev May 08 '14 at 17:14
  • @toprightgamedev then _what is your server_? – bwoebi May 09 '14 at 21:41
  • It's Apache/2.2.22 at Ubuntu (Linux 2.6.32-5-xen-amd64). – topright gamedev May 10 '14 at 14:38
  • 1
    Have you checked the Apache Log if your request at least hits Apache? If this is not the case, the problem may lie clientside. – D. Schalla May 14 '14 at 08:59

0 Answers0