YAWS Websocket 问题

发布于 2024-12-11 09:19:11 字数 1060 浏览 0 评论 0原文

我正在尝试从 YAWS websocket 示例获取 YAWS websocket 示例.hyber.org/websockets_example.yaws" rel="nofollow">此处 在我的本地运行。它是一个基本的基于 ws 的 echo 服务器。

我已经

  • localhost:8080 上设置并运行了 YAWS(直接来自 Debian 存储库;除了将其指向新的根目录之外,没有任何配置更改)
  • 此页面包含在 标记中,另存为websockets_example_endpoint.yaws
  • 此页面另存为index.yaws< /code> (我确实复制/粘贴了它的视图源,将其保存为该文件并将套接字请求指向 localhost:8080 而不是yaws.hyber.org)。

当我在浏览器中访问 localhost:8080/websockets_example_endpoint.yaws 时,它会按预期显示文本“您不是 Web 套接字客户端!走开!”。当我访问 localhost:8080 时,它会将我指向启用 JavaScript 的表单,但单击“连接”按钮时不会执行任何操作。如果我将 index.yaws 指向 yaws.hyber.org 而不是 localhost:8080,则 echo 服务器将完全按预期连接并工作。

谁能给我提示我做错了什么(或者指出我的工作示例来源)?

I'm trying to get the YAWS websocket example from here running on my local. It's a basic ws-based echo server.

I have

  • YAWS set up and running on localhost:8080 (direct from the Debian repos; no conf changes except pointing it to a new root directory)
  • the code listing from the bottom of this page wrapped in <erl> tags saved as websockets_example_endpoint.yaws
  • this page saved as index.yaws (I literally copy/pasted the view-source for it, saved it as that file and pointed the socket request at localhost:8080 rather than yaws.hyber.org).

When I visit localhost:8080/websockets_example_endpoint.yaws in-browser, it displays the text "You're not a web sockets client! Go away!", as expected. When I visit localhost:8080, it points me to the javascript enabled form, but the "Connect" button does nothing when clicked. If I leave index.yaws pointed at yaws.hyber.org instead of localhost:8080, the echo server connects and works exactly as expected.

Can anyone give me a hint as to what I'm doing wrong (or alternatively, point me to source for a working example)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可可 2024-12-18 09:19:11

我创建了一个 gitbub 项目:
https://github.com/f3r3nc/yaws-web-chat/

这是也是嵌入雅司病并通过群聊扩展的示例。

请注意,WebSocket 标准正在开发中,因此浏览器应该支持相同的 WS 版本才能正常工作。

雅司病 1.91 适用于 Safari 版本 5.1.1 (6534.51.22),但不适用于 Chrome (15.0.874.102),可能不适用于 (14.x)。

There is a gitbub project, I've created:
https://github.com/f3r3nc/yaws-web-chat/

This is also an example for embedding yaws and extended with group chat.

Note, that the standard of WebSocket is under development thus yaws and the browser should support the same WS version in order to work correctly.

yaws 1.91 works with Safari Version 5.1.1 (6534.51.22) but does not with Chrome (15.0.874.102) and probably not with (14.x).

世界和平 2024-12-18 09:19:11

对我来说,问题是我没有 basic_echo_callback 模块文件,因为我使用包存储库而不是构建表单源安装了 yaws。

如果在交互模式“yaws -i”下运行 yaws,则错误很明显:

=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Cannot load callback module 'basic_echo_callback': nofile
=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Failed to start websocket process: nofileq

这几乎是我在 Ubuntu 16.01 上从头开始的过程:

sudo apt install yaws
cd ~
mkdir yaws
cd yaws

mkdir src
cd src
cd src wget https://github.com/klacke/yaws/raw/master/examples/src/basic_echo_callback.erl
cd ..

mkdir www
cd www
wget https://raw.githubusercontent.com/klacke/yaws/master/www/websockets_example_endpoint.yaws
wget http://yaws.hyber.org/websockets_example.yaws
cd ..

#set-up server config file...
vim yaws.conf

我的看起来像:

src_dir = /home/pocketsand/yaws/src
<server localhost>
  port = 8000
  listen = 127.0.0.1
  docroot = /home/pocketsand/yaws/www
</server>

确保客户端中的端点正确:

vim www/websockets_example.yaws
...

停止服务器,如果已经运行并使用“yaws -i”启动服务器并浏览到:http://localhost:8000/websockets_example.yaws

它之所以有效,是因为每次服务器加载配置文件时,它都会编译指定 src 目录中的任何模块。如果缺少其他功能的其他模块,也需要下载它们。

For me the problem was I did not have the basic_echo_callback module file because I installed yaws using a package repository rather than building form source.

The error was evident if running yaws in interactive mode ´yaws -i´:

=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Cannot load callback module 'basic_echo_callback': nofile
=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Failed to start websocket process: nofileq

This is pretty much my process from scratch on Ubuntu 16.01:

sudo apt install yaws
cd ~
mkdir yaws
cd yaws

mkdir src
cd src
cd src wget https://github.com/klacke/yaws/raw/master/examples/src/basic_echo_callback.erl
cd ..

mkdir www
cd www
wget https://raw.githubusercontent.com/klacke/yaws/master/www/websockets_example_endpoint.yaws
wget http://yaws.hyber.org/websockets_example.yaws
cd ..

#set-up server config file...
vim yaws.conf

Mine looks like:

src_dir = /home/pocketsand/yaws/src
<server localhost>
  port = 8000
  listen = 127.0.0.1
  docroot = /home/pocketsand/yaws/www
</server>

Ensure endpoint is correct in the client:

vim www/websockets_example.yaws
...

Stop server if already running and start server with ´yaws -i´ and browse to: http://localhost:8000/websockets_example.yaws

It works because each time the server loads the configuration file it will compile any modules in the specified src directory. If other modules are missing for the other features they will also need to be downloaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文