简体   繁体   English

如何在 Puma 服务器的现有端口上初始化 Websocket?

[英]How to initialize a Websocket on existing port in Puma server?

I have a ruby application in which I am using puma web server which listens on port 8008.我有一个 ruby​​ 应用程序,我在其中使用 puma Web 服务器,它侦听端口 8008。

Now I have got requirement to implement socket.io/websockets.现在我需要实现socket.io/websockets。

I was exploring the possibility of using EventMachine::WebSocket but since my puma application is already using port 8008, I cannot bind to 8008.我正在探索使用 EventMachine::WebSocket 的可能性,但由于我的 puma 应用程序已经在使用端口 8008,我无法绑定到 8008。

My UI is written in javascript and puma application basically exposes rest endpoints.我的 UI 是用 javascript 编写的,puma 应用程序基本上公开了其余的端点。

How can I implement websockets in such a scenario?在这种情况下如何实现 websockets?

I'd leave the Rails server on the port it's running on, and redirect your websocket requests to the other server which runs on a different port.我会将 Rails 服务器留在它运行的端口上,并将您的 websocket 请求重定向到在不同端口上运行的另一台服务器。

This question/answer essentially describes the implementation. 这个问题/答案基本上描述了实现。 So you'd probably want something like:所以你可能想要这样的东西:

match "/websocket/(*path)" => redirect {|params, req| "http://your.domain:8009/#{params[:path]}"}

where 8009 is the port your Websocket server runs on.其中 8009 是您的 Websocket 服务器运行的端口。

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

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