简体   繁体   中英

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

I'm starting with Websockets and I have a problem. I have a sails.js application that uses sockets to update the client side.

On the client side it makes an API call using socket.get("/api/v1/actor...") to bring all the items of the database. When I see what the WebSocket's traffic on the Chrome console:

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

As you can see, the connection has been established and the API call has been correctly done through the socket. 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. 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

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.

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').

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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