6

I had a need to connect to websocket via php, send data and immediately disconnect. No need to wait for a response from the socket. I used elefant.io but after updating the library does not work. Please tell me how to connect to websocket via PHP?

DuckHunter
  • 91
  • 1
  • 6

2 Answers2

8

I also encountered this problem. Learned a lot of structure websocket requests. I wrote a library for yourself, you can use it.PHP SocketIO Client.

You need simple socket connect to nodejs, compose in this message format.42["message", "your message"]' To encode to hybi10 (or hybi13) and send to websocket

SlyBeaver
  • 1,272
  • 12
  • 22
  • Also, you can download any websoket library, but edit and put something like $header .= "GET /socket.io/?EIO=2&transport=websocket HTTP/1.1\r\n"; to socket.io server library work. Spent 2 hours trying to understand – Velaro Jan 15 '19 at 14:11
-3
var socket = require( 'socket.io' );

var express = require( 'express' );

var http = require( 'http' );

var app = express();

var server = http.createServer( app );

var io = socket.listen( server );

io.sockets.on( 'connection', function( client ) {

console.log( "New client !" );
Cyrus Mohammadian
  • 4,982
  • 6
  • 33
  • 62
deibu
  • 1
  • 3