我正在使用 WildFly 10.1..0.Final,我想使用 STOMP over WebSocket 连接 JavaScript 客户端。我正在使用 stomp.js。WildFly 包括 Apache ActiveMQ Artemis Message Broker 版本 1.1.0.wildfly-017。
首先,我使用 add-user.bat 添加了一个名为“myguest”的用户。该用户是“应用程序用户”。
接下来,我尝试了许多不同的方法来配置主题和安全设置。请检查我尝试配置主题的不同方式。两者都不起作用。
我尝试创建“jms.topic.chat”主题和一些变体。别工作。
我的standalone-full.xml 是:
...
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
<role name="myguest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<security-setting name="jms.topic.chat">
<role name="myguest" send="true" consume="true" create-durable-queue="true" delete-durable-queue="true" create-non-durable-queue="true" delete-non-durable-queue="true" manage="true"/>
<role name="guest" send="true" consume="true" create-durable-queue="true" delete-durable-queue="true" create-non-durable-queue="true" delete-non-durable-queue="true" manage="true"/>
</security-setting>
<security-setting name="topic.chat">
<role name="myguest" send="true" consume="true" create-durable-queue="true" delete-durable-queue="true" create-non-durable-queue="true" delete-non-durable-queue="true" manage="true"/>
<role name="guest" send="true" …Run Code Online (Sandbox Code Playgroud) 我正在使用 node.js 的 Express 框架制作一个应用程序,该框架通过 http 提供 html 内容,并使用 websockets 实现聊天功能。我想知道如何才能同时完成这两件事。我的想法是使用不同的端口进行 websocket 连接(因此 http 请求将到达端口 3000,而 websocket 将在端口 3001 上连接),但我不知道这是否是一个好的解决方案。我特别担心部署到像 heroku 这样的东西,以及我是否可以为我的应用程序指定不同的端口。
我有一个简单的 Node js Web 套接字服务器,如下所示:
var ws = require("nodejs-websocket")
var connectionCount = 0;
console.info("Node websocket started @ 8001");
var server = ws.createServer(function (conn) {;
console.log("New connection", ++connectionCount);
conn.on("close", function (code, reason) {
console.log("Connection closed")
});
}).listen(8001)
Run Code Online (Sandbox Code Playgroud)
该服务器需要 65k 个连接(因为一个端口最多需要 65k 个连接)。如何扩展服务器以使其能够容纳超过 100k 个连接?
我最近打开了三个具有不同端口的此类服务器,并尝试使用 nginx 进行负载平衡,但无济于事,因为 nginx 服务器也只能接受 65k 连接。nginx 配置在这里
upstream localhost {
server localhost:8001;
server localhost:8002;
server localhost:8003;
}
server {
proxy_read_timeout 3600s;
listen 8000;
location / {
proxy_pass http://localhost;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; …Run Code Online (Sandbox Code Playgroud) 如果我理解正确的话,跨文档消息传递 API 允许您在网页之间实时发送和接收消息。
而 WebSocket 允许您在网站和服务器之间实时发送和接收对象。
是否可以替代另一个来实时构建 Web 应用程序?
如果不是,哪种机制更好,为了什么?
我想使用以下websocket 天气 api。
我尝试调整以下示例,但没有取得任何进展。
import asyncio
import websockets
async def hello():
async with websockets.connect('ws://ws.weatherflow.com/swd/data') as websocket:
await websocket.send({
"type":"listen_start",
"device_id":1110,
"id":"2098388936"
})
greeting = await websocket.recv()
print(greeting)
asyncio.get_event_loop().run_until_complete(hello())
Run Code Online (Sandbox Code Playgroud)
如何在Python中使用websocket api?那就是如何获取源源不断的天气信息呢?
我正在尝试制作一个使用 WebSockets 的 Flask 应用程序。Flask-sockets 中的示例有效,但我如何从常规视图发送消息?
.emit()与 Flask-SocketIO 如何使用和方法类似.send()。
在下面的示例中(来自 Flask-Sockets 示例),我希望能够从 -view 广播消息hello。
from flask import Flask
from flask_sockets import Sockets
app = Flask(__name__)
sockets = Sockets(app)
@sockets.route('/echo')
def echo_socket(ws):
while not ws.closed:
message = ws.receive()
ws.send(message)
@app.route('/')
def hello():
# How can I send a WebSocket message from here?
return 'Hello World!'
if __name__ == "__main__":
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
server.serve_forever()
Run Code Online (Sandbox Code Playgroud) 从观察者的角度来看,症状与此处的问题相同 场景也相同:Angular 应用程序将预检请求发送到 REST api,并且预检请求大约需要 50% 的时间,最多 1.3 秒(插图与链接的问题)。
此外,websocket 经常超时,直到 socket-io 最终成功建立连接。问题在 Chrome 中更为明显,而在 Safari/Firefox 中则较少。
但是,我们使用的是 ALB 而不是 ELB,并且我们所有的子网都是公共的。
amazon-web-services websocket socket.io amazon-elb amazon-alb
我认为我的问题很简单也很愚蠢,但是我读了很多材料,无法想象如何做我想要的事情。
所以,我使用websockets库,并且我有这个算法:
# 1. get connection and start handle it
async def main_request_handler(ws, path):
proxy = Proxy()
try:
await proxy.start(ws, path)
Run Code Online (Sandbox Code Playgroud)
2.在start内部我创建第二个websocket来传递请求ws并接收答案并将其发送到ws
while True:
request_raw = await self.ws_server.recv()
await self.process_request_from_server(request_raw)
Run Code Online (Sandbox Code Playgroud)
问题是,我需要为多个
ws客户端使用一个 websocket 服务器连接,并且我需要向每个人传递相同的答案ws_server。现在我只得到一个响应,因为 .recv() 仅返回其中一个“订阅者”的值。如何解决这个问题?请注意,我使用while True和async
我想在 Spring Boot 应用程序中使用 java websocket API。我创建了以下类,如下所述: https: //www.baeldung.com/java-websockets
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
@ServerEndpoint(value = "/test")
public class FrontendEndpoint {
@OnOpen
public void onOpen(Session session) throws IOException {
session.getBasicRemote().sendText("Test");
}
@OnMessage
public void onMessage(Session session, String message) throws IOException {
}
@OnClose
public void onClose(Session session) throws IOException {
}
@OnError
public void onError(Session session, Throwable throwable) {
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试连接到该 websocket 但没有任何反应。我在互联网上看到了很多文章,但没有任何帮助我。我不知道如何让它发挥作用。
当我尝试连接到 websocket 时没有发生任何事情。
春季启动版本:2.0.3
Websocket-API 版本:1.1
我也没有看到 websocket 的开放端口。
谢谢
BR
websocketstart()
{
exampleSocket = new WebSocket('ws://127.0.0.1:8000');
exampleSocket.onopen = function() {
// alert('handshake successfully established. May send data now...');
// exampleSocket.send('hello!!!')
};
exampleSocket.onmessage = function(event) {
let result = JSON.parse(event.data);
if(result.error == false)
{
console.log("ERROR : " + result.parent.message);
alert('error');
return;
}
this.wantcallfunction(); //<---- SCRIPT438: Object doesn't support property or method 'wantcallfunction'
return;
};
exampleSocket.onclose = function() {
alert('connection closed');
};
}
wantcallfunction()
{
}
Run Code Online (Sandbox Code Playgroud)
this.wantcallfunction(); //<---- SCRIPT438:对象不支持属性或方法“wantcallfunction”
还有其他方法可以从 onmessage 中调用该函数吗?
websocket ×10
python ×3
javascript ×2
amazon-alb ×1
amazon-elb ×1
c10k ×1
express ×1
flask ×1
gevent ×1
html ×1
java ×1
nginx ×1
node.js ×1
port ×1
python-3.x ×1
scalability ×1
socket.io ×1
spring ×1
spring-boot ×1
stomp ×1
wildfly ×1