Erlang 如何使用Yaws处理appmod中的WebSocket消息?

Erlang 如何使用Yaws处理appmod中的WebSocket消息?,erlang,websocket,yaws,Erlang,Websocket,Yaws,我创建了一个简单的appmod,它发送回与接收到的消息相同的消息。但我在命令提示下收到一条错误消息,WebSocket连接关闭 如果我发送一条包含3个字符的消息,我会收到以下错误消息: =ERROR REPORT==== 8-Feb-2012::05:09:14 === Error in process <0.59.0> with exit value: {undef,[{mywebsocket,handle_message,[ {text,<<3 bytes>&g

我创建了一个简单的appmod,它发送回与接收到的消息相同的消息。但我在命令提示下收到一条错误消息,WebSocket连接关闭

如果我发送一条包含3个字符的消息,我会收到以下错误消息:

=ERROR REPORT==== 8-Feb-2012::05:09:14 ===
Error in process <0.59.0> with exit value: {undef,[{mywebsocket,handle_message,[
{text,<<3 bytes>>}],[]},{lists,map,2,[{file,"lists.erl"},{line,1173}]},{yaws_web
sockets,loop,4,[{file,"yaws_websockets.erl"},{line,151}]}]}
从客户端连接时调用的My
ws.yaws
如下所示:

<erl>
out(A) -> {websocket, mywebsocket, []}.
</erl>
-module(mywebsocket).
-export([handle_message/1]).

handle_message({text, Message}) ->
    {reply, {text, Message}}.
<server localhost>
    port = 8090
    listen = 0.0.0.0
    docroot = "C:\Users\Jonas/yawswww"
    appmods = <ws, mywebsocket>
</server>
# This the path to a directory where additional
# beam code can be placed. The daemon will add this
# directory to its search path

ebin_dir = "F:/programming work/erlcharts-1.0/ebin"
ebin_dir = "C:/SomeFolder/another_library-1.0/ebin"
ebin_dir = "D:/Any/Folder/myappmods"

# This is a directory where application specific .hrl
# files can be placed. application specifig .yaws code can
# then include these .hrl files

include_dir = "C:\Program Files (x86)\Yaws-1.90/examples/include"
include_dir = "D:/Any/Folder/myappmods/include"
yaws.conf
中,我对服务器进行了如下配置:

<erl>
out(A) -> {websocket, mywebsocket, []}.
</erl>
-module(mywebsocket).
-export([handle_message/1]).

handle_message({text, Message}) ->
    {reply, {text, Message}}.
<server localhost>
    port = 8090
    listen = 0.0.0.0
    docroot = "C:\Users\Jonas/yawswww"
    appmods = <ws, mywebsocket>
</server>
# This the path to a directory where additional
# beam code can be placed. The daemon will add this
# directory to its search path

ebin_dir = "F:/programming work/erlcharts-1.0/ebin"
ebin_dir = "C:/SomeFolder/another_library-1.0/ebin"
ebin_dir = "D:/Any/Folder/myappmods"

# This is a directory where application specific .hrl
# files can be placed. application specifig .yaws code can
# then include these .hrl files

include_dir = "C:\Program Files (x86)\Yaws-1.90/examples/include"
include_dir = "D:/Any/Folder/myappmods/include"

端口=8090
听=0.0.0.0
docroot=“C:\Users\Jonas/yawswww”
appmods=

我使用Yaws 1.92和Chrome 16。

可能是因为您的appmod不在路径中,或者它的模块没有加载到Yaws web server VM实例或shell中。web服务器启动后,尝试在yaws shell中调用此方法: 1> mywebsocket:handle_message({text,"Some Data"}). 现在,在yaws-conf文件中输入所有代码的路径。不要担心前斜杠或后斜杠,雅司病总是绕着路径走。对于UNIX/LINUX,它保持不变,例如
ebin_dir=“/usr/local/lib/erlang/lib/myapp-1.0/ebin”


但是,请注意,在yaws web server完全初始化之前,您的模块将不会被加载。

谢谢,这是有效的。我还把你其他帖子的内容添加到了这个答案中。你应该编辑你的答案,而不是发布新的答案。