简体   繁体   English

在航行中使用WebSocket发出请求,但未收到服务器的响应

[英]Making request using WebSockets in sails but not receiving response from the server

I'm starting with Websockets and I have a problem. 我从Websockets开始,但遇到了问题。 I have a sails.js application that uses sockets to update the client side. 我有一个使用套接字更新客户端的sails.js应用程序。

On the client side it makes an API call using socket.get("/api/v1/actor...") to bring all the items of the database. 在客户端,它使用socket.get("/api/v1/actor...")进行API调用,以带入数据库的所有项目。 When I see what the WebSocket's traffic on the Chrome console: 当我在Chrome控制台上看到WebSocket的流量时:

使用socket.get执行API调用后的Chrome控制台

As you can see, the connection has been established and the API call has been correctly done through the socket. 如您所见,连接已经建立,并且API调用已通过套接字正确完成。 The problem is, there is no answer from the server, not even an error. 问题是,服务器没有答案,甚至没有错误。

If I make the same API call using ajax, I get response, but it doesn't work using WebSockets. 如果我使用ajax进行相同的API调用,则会得到响应,但使用WebSockets无效。 Any idea what might be producing this behavior? 任何想法可能会产生这种行为吗?

EDIT: I add here the code here that processes the request and this one here that sends the request, but the problem is that it never execute this code. 编辑:我在这里添加代码在这里处理该请求,这一次在这里发送请求,但问题是,它从来没有执行该代码。 I think we we are closer to the find the cause, since we think it has to do with a network problem. 我认为我们离找到原因更近了,因为我们认为这与网络问题有关。 We figured there is an F5 reverse-proxy which is not properly set up to handle websockets 我们发现有一个F5反向代理,该代理未正确设置以处理WebSocket

The answer didn't make any sense now that I've seen the code that's why I've edited it. 现在,我已经看过代码,因此无法进行编辑,因此答案变得毫无意义。 I only answered because I could't comment on your question and ask you for the code. 我之所以回答,是因为我无法评论您的问题并要求您提供代码。

Your calling code seems correct and the server side of things the process of response should be handled automatically by the framework, you only need to return some JSON in the controller method. 您的调用代码似乎是正确的,并且响应过程应该在服务器端由框架自动处理,您只需要在controller方法中返回一些JSON。

I instantiated a copy of the server (just changed the adapters to run it locally) and the server replied to the web socket requests (although I only tested the route '/index'). 我实例化了服务器的副本(只是更改了适配器以在本地运行它),服务器回复了Web套接字请求(尽管我只测试了路由“ / index”)。

Normally when the problems are caused by a reverse proxy the socket simply refuses to connect and you can't even send data to server. 通常,当问题是由反向代理引起的时,套接字只是拒绝连接,甚至不能将数据发送到服务器。 Does the property "socket.socket.connected" returns true? 属性“ socket.socket.connected”是否返回true?

The best way to test is to write a small node application with socket.io client and test it in the same machine that the application server is running, then you can exclude network problems. 最好的测试方法是使用socket.io客户端编写一个小型节点应用程序,并在运行应用程序服务器的同一台计算机上对其进行测试,然后可以排除网络问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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