简体   繁体   中英

Connect to socket.io(nodejs) via PHP

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?

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

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 !" );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM