[英]Connect to socket.io(nodejs) via PHP
I had a need to connect to websocket via php, send data and immediately disconnect. 我需要通过php连接到websocket,发送数据并立即断开连接。 No need to wait for a response from the socket.
无需等待套接字的响应。 I used elefant.io but after updating the library does not work.
我使用elefant.io但更新后的库不起作用。 Please tell me how to connect to websocket via PHP?
请告诉我如何通过PHP连接到websocket?
I also encountered this problem. 我也遇到过这个问题。 Learned a lot of structure websocket requests.
了解了很多结构websocket请求。 I wrote a library for yourself, you can use it.
我为自己写了一个库,你可以使用它。 PHP SocketIO Client .
PHP SocketIO客户端 。
You need simple socket connect to nodejs, compose in this message format. 您需要简单的套接字连接到nodejs,以此消息格式组合。
42["message", "your message"]
' To encode to hybi10 (or hybi13) and send to websocket 42["message", "your message"]
'编码为hybi10(或hybi13)并发送到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 !" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.