Socket.io 套接字.io+;AWS API网关套接字继续重新连接,并且从不触发connect

Socket.io 套接字.io+;AWS API网关套接字继续重新连接,并且从不触发connect,socket.io,aws-api-gateway,Socket.io,Aws Api Gateway,AWS最近推出了带有套接字的API网关,它可以代理lambda。在我的观察中,AWS api套接字完全是wss的,因此我在代码部分中做了自定义connect设置。如本链接所述,我学习的lambda和其他设置使用wscat成功测试- 但在与浏览器中的socket.io集成时,它只会在18-19秒后继续重新连接,并且永远不会触发连接!lambda和api网关超时为30秒,我认为可以忽略,因为它不会中断与wscat的连接4-5分钟 我不熟悉套接字,注释中的代码显示尝试失败。也尝试过谷歌搜索,但找不到

AWS最近推出了带有套接字的API网关,它可以代理lambda。在我的观察中,AWS api套接字完全是wss的,因此我在代码部分中做了自定义
connect
设置。如本链接所述,我学习的lambda和其他设置使用wscat成功测试-

但在与浏览器中的socket.io集成时,它只会在18-19秒后继续重新连接,并且永远不会触发连接!lambda和api网关超时为30秒,我认为可以忽略,因为它不会中断与wscat的连接4-5分钟

我不熟悉套接字,注释中的代码显示尝试失败。也尝试过谷歌搜索,但找不到关于AWSAPI套接字和socket.io的更多信息。因此,我们非常感谢您的指导或支持

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
</head>
<script>
    socket = io(
        `wss://abcd.execute-api.us-east-1.amazonaws.com/prod`
        , {
        path: `/prod/`,
        forceNew: true,
        // autoConnect: false,
        // reconnection: false,
        upgrade: true,
        transports: ['websocket',
        'polling',
        'flashsocket'
        ]
    });

    socket.on('connect', function () {
        socket.emit({"action":'message',"data":"hello return"}, () => {
          console.log("message Sent");
        });
  });

//         socket.emit({"action":'message',"data":"hello return"}, () => {
//           console.log("message"); // true
//         });
//         socket.on('message', () => {
//         console.log("message"); // true
//       });

//       socket.on("connection", function (socket) {
//     console.log("connection")
//   })

//       socket.on('connect', () => {
//       console.log("connect"); // true
//     });

//   socket.on('connected', () => {
//       console.log("connected"); // true
//     });

//     socket.on('open', () => {
//       console.log("open"); // true
//     });

//   socket.on('disconnect', (reason) => {
//    console.log("disconnect->",reason);
//    // if (reason === 'io server disconnect') {
//     //   // the disconnection was initiated by the server, you need to reconnect manually
//     //   socket.connect();
//     // }
//     // else the socket will automatically try to reconnect
//   });

//   socket.on('close', (reason) => {
//    console.log("close->",reason);
//    // if (reason === 'io server disconnect') {
//     //   // the disconnection was initiated by the server, you need to reconnect manually
//     //   socket.connect();
//     // }
//     // else the socket will automatically try to reconnect
//   });

//   // socket.open();
//   // console.log(socket);

//   socket.on( (res) => {
//     console.log("res", res);
//   });



//   socket.on('reconnect', (attemptNumber) => {
//     console.log("reconnected", attemptNumber); // true
//   });

//   socket.on('reconnecting', (attemptNumber) => {
//     console.log("reconnecting...", attemptNumber); // true
//   });

//   socket.on('reconnect_error', (error) => {
//     console.log("reconnect_error",error);
//   });

//   socket.on('reconnect_attempt', (error) => {
//     console.log("reconnect_attempt->", error)
//     // socket.io.opts.transports = ['polling', 'websocket'];
//   });

//   socket.on('error', (error) => {
//     console.log("error->", error);
//   });



//   socket.on('ping', () => {
//     console.log("ping");
//   });

//   socket.on('pong', () => {
//     console.log("ping");
//   });


  </script>
</html>

套接字=io(
`wss://abcd.execute-api.us-east-1.amazonaws.com/prod`
, {
路径:`/prod/`,
forceNew:是的,
//自动连接:错误,
//重新连接:错误,
升级:对,
传输:['websocket',
"投票",,
“闪光插座”
]
});
socket.on('connect',function(){
emit({“action”:“message”,“data”:“hello return”},()=>{
控制台日志(“已发送消息”);
});
});
//emit({“action”:“message”,“data”:“hello return”},()=>{
//console.log(“message”);//true
//         });
//socket.on('message',()=>{
//console.log(“message”);//true
//       });
//socket.on(“连接”),函数(socket){
//console.log(“连接”)
//   })
//socket.on('connect',()=>{
//console.log(“connect”);//true
//     });
//socket.on('已连接',()=>{
//console.log(“已连接”);//true
//     });
//socket.on('open',()=>{
//console.log(“打开”);//true
//     });
//socket.on('断开连接',(原因)=>{
//日志(“断开->”,原因);
////如果(原因==“io服务器断开连接”){
/////断开连接是由服务器启动的,您需要手动重新连接
////socket.connect();
//     // }
////否则套接字将自动尝试重新连接
//   });
//socket.on('关闭',(原因)=>{
//console.log(“关闭->”,原因);
////如果(原因==“io服务器断开连接”){
/////断开连接是由服务器启动的,您需要手动重新连接
////socket.connect();
//     // }
////否则套接字将自动尝试重新连接
//   });
////socket.open();
////console.log(套接字);
//socket.on((res)=>{
//控制台日志(“res”,res);
//   });
//socket.on('重新连接',(尝试编号)=>{
//console.log(“已重新连接”,尝试编号);//true
//   });
//socket.on('重新连接',(尝试编号)=>{
//console.log(“重新连接…”,attemptNumber);//true
//   });
//socket.on('reconnect_error',(error)=>{
//日志(“重新连接错误”,错误);
//   });
//socket.on('重新连接\u尝试',(错误)=>{
//日志(“重新连接尝试->”,错误)
////socket.io.opts.transports=['polling','websocket'];
//   });
//socket.on('error',(error)=>{
//log(“error->”,error);
//   });
//socket.on('ping',()=>{
//控制台日志(“ping”);
//   });
//socket.on('pong',()=>{
//控制台日志(“ping”);
//   });

我也有同样的问题。你找到什么了吗?没有,只是努力了。人们不怎么使用AWS,我想现在一年了,没有多少医生。我放弃了,用原生WebSocket JS库替换了Socket.io。Socket.io文档说,他们没有严格遵循WebSocket关于头的标准(根据他们的说法,也没有办法更改它们),因此这可以解释为什么不能与AWS建立连接。Good research@HansAraya您尝试过本机WebSocket库吗?在我的情况下,它每5分钟就断开一次。是的,当然断开了。您必须实现keep-alive/ping-pong/heartbeat特性(如中指定的)。我不确定Socket.IO是否能做到这一点,但它可能是从后面做到的。