gpt4 book ai didi

php - fatal error : Uncaught UnexpectedValueException: The server returned an unexpected value. 应为 "HTTP/1.1 101",实际为 ""

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:30 25 4
gpt4 key购买 nike

我是socketIO和elephantIO的新手,我正在尝试从php文件emit_test.php发送到 Node 服务器,如下所示

ini_set("display_errors",5);
include ("vendor/autoload.php");

use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version1X;
$version = new Version1X("http://localhost:3001");
$client = new Client($version);

$client->initialize();
$client->emit("new_order", ["test"=>"test", "test1"=>"test1"]);
$client->close();

server.js 文件

var socket = require('socket.io');
var express = require('express');
var https = require('https');
var http = require('http');
var logger = require('winston');

logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {colorize: true, timestamp: true})

logger.info('SocketIO > listening on port ');

var app = express();
var http_server = http.createServer(app).listen(3001);

function emitNewOrder(http_server){
var io = socket.listen(http_server);

//first listen to a connection and run the call back function
io.sockets.on('connection', function (socket) {

socket.on("new_order", function(data){
console.log(data);
//io.emit("new_order", data)
})

})
}

emitNewOrder(http_server);

我希望将emit_test.php 文件中的数据记录到接收器php 文件中与代码

<script>

var socket = io.connect("http://localhost:3001");


socket.on("new_order", function (data) {
console.log(data);

});
</script>

但是在运行服务器时我收到错误:

fatal error :未捕获UnexpectedValueException:服务器返回意外值。应为“HTTP/1.1 101”,实际为“”

请问有什么帮助吗?

最佳答案

我也遇到了同样的问题。

我通过更改 ElephantIO 的版本修复了该问题。

在emit_test.php中我更改:

use ElephantIO\Engine\SocketIO\Version1X;
$version = new Version1X("http://localhost:3001");

到这个版本

use ElephantIO\Engine\SocketIO\Version2X;
$version = new Version2X("http://localhost:3001");

关于php - fatal error : Uncaught UnexpectedValueException: The server returned an unexpected value. 应为 "HTTP/1.1 101",实际为 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44828697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com