简体   繁体   English

如何解决 Websocket Rxjs 中的缓冲值问题? 发送消息不是 go 到服务器,而是存储在缓冲区中

[英]How to resolve a buffered values issue in Websocket Rxjs? Sending a message doesn't go to the server but gets stored in buffer

I am using Websocket Rxjs in my application.我在我的应用程序中使用 Websocket Rxjs。 My connection gets established with the server and after subscribing to it I receive all the data in an array.我与服务器建立了连接,在订阅它之后,我收到了一个数组中的所有数据。 Now when I try to send the some data back to the server, it just doesn't send, it get's stored in the buffer array of destination object of websocket observable (screenshot below).现在,当我尝试将一些数据发送回服务器时,它只是不发送,它被存储在 websocket 可观察的目标 object 的缓冲区数组中(下面的屏幕截图)。 I am sharing the snippet of the code also.我也在分享代码片段。

 import { webSocket } from 'rxjs/webSocket';

const subject = webSocket('ws://localhost:8081');

subject.subscribe({
  next: msg => console.log('message received: ' + msg),
  error: err => console.log(err), 
  complete: () => console.log('complete') 
});


// Upon clicking a button I send this to the sever. You can see it in the screenshot.
subject.next({
    "action" : "read",
    "id" : 1595
});

在此处输入图像描述

My connection remains active though.我的连接仍然有效。 It doesn't gets closed but still I am facing this issue.它没有关闭,但我仍然面临这个问题。 What could be the issue with this?这可能是什么问题? Is it something with the backend?跟后台有关系吗? If yes, then what could it be?如果是,那会是什么? Any help will be appreciated.任何帮助将不胜感激。 Thank you.谢谢你。 :) :)

It seems that the problem is in your websocket server, but to be sure try instead to connect to a test server like the echo server of Postman: wss://ws.postman-echo.com/raw看来问题出在您的 websocket 服务器上,但请务必尝试连接到测试服务器,例如 Postman 的回显服务器:wss://ws.postman-echo.com/raw

In each time the client sends a message to this server it will send it back to the client directly.每次客户端向该服务器发送消息时,它都会将其直接发送回客户端。

By the way: Postman now has the possibility yo to connect to your websocket server and test it.顺便说一句:Postman 现在可以连接到您的 websocket 服务器并进行测试了。

Here you can read how to do that: https://blog.postman.com/postman-supports-websocket-apis/在这里你可以阅读如何做到这一点: https://blog.postman.com/postman-supports-websocket-apis/

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

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