Connect to socket.io(nodejs) via PHP

核能气质少年 提交于 2019-12-04 12:17:41

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/24948669/connect-to-socket-ionodejs-via-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!