2

我正在尝试从这里在我的本地运行YAWS websocket示例。它是一个基本的基于 ws 的回显服务器。

我有

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

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

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

4

2 回答 2

2

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

这也是嵌入偏航和扩展群聊的示例。

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

yaws 1.91 适用于 Safari 版本 5.1.1 (6534.51.22) 但不适用于 Chrome (15.0.874.102) 并且可能不适用于 (14.x)。

于 2011-10-26T14:43:28.693 回答
0

对我来说,问题是我没有 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 目录中的任何模块。如果其他功能缺少其他模块,则也需要下载它们。

于 2016-12-07T22:10:05.507 回答