Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:57:00+00:00 2026-05-29T08:57:00+00:00

I have created a simple appmod that sends back the same message as it

  • 0

I have created a simple appmod that sends back the same message as it receives. But I get an error message at the command prompt and the WebSocket connection is closed.

If I send a message with 3 chars I get this error message:

=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}]}]}

What am I doing wrong? The handle uses text, and it doesn’t work if I use binary either.

Here is my HTML+JavaScript client:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script>
window.onload = function() {
    document.getElementById('sendbutton').addEventListener('click', sendMessage, false);
    document.getElementById('connectbutton').addEventListener('click', connect, false);
    document.getElementById('disconnectbutton').addEventListener('click', disconnect, false);
}

function writeStatus(message) {
    var html = document.createElement("div");
    html.setAttribute("class", "message");
    html.innerHTML = message;
    document.getElementById("status").appendChild(html);
}

function connect() {
    ws = new WebSocket("ws://localhost:8090/ws.yaws");

    ws.onopen = function(evt) {
        writeStatus("connected");
    }

    ws.onclose = function(evt) {
        writeStatus("disconnected");
    }

    ws.onmessage = function(evt) {
        writeStatus("response: " + evt.data);
    }

    ws.onerror = function(evt) {
        writeStatus("error: " + evt.data);
    }
}

function disconnect() {
    ws.close();
}

function sendMessage() {
    var msg = document.getElementById('messagefield').value
    ws.send(msg);
}
</script>
</head>
<body>
<h1>Chat</h1>
<button id="connectbutton">Connect</button>
<button id="disconnectbutton">Disconnect</button><br/>
<input type="text" id="messagefield"/><button id="sendbutton">Send</button>
<div id="status"></div>
</body>
</html>

My ws.yaws that is called on connection from the client looks like this:

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

And my callback appmod mywebsocket.erl looks like this:

-module(mywebsocket).
-export([handle_message/1]).

handle_message({text, Message}) ->
    {reply, {text, Message}}.

In yaws.conf I have configured the server like this:

<server localhost>
    port = 8090
    listen = 0.0.0.0
    docroot = "C:\Users\Jonas/yawswww"
    appmods = <ws, mywebsocket>
</server>

I use Yaws 1.92 and Chrome 16.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:57:01+00:00Added an answer on May 29, 2026 at 8:57 am

    Probably, your appmod is not in PATH, or its module is not loaded in the yaws web server VM instance or shell. Try to call this method in the yaws shell once your web server starts:

    1> mywebsocket:handle_message({text,"Some Data"}).
    

    If it runs very well in the yaws shell, then it means that its in PATH. The error is undef meaning that the function call is failing because the module in which the function is contained, is not loaded.


    Now, in the yaws.conf file, edit it to include the ebin folder where the compiled file of your appmod exists. Actually make sure to add all PATHS to executable code that your appmod depends on. it should appear like this:

    # 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"
    

    Now, enter the PATHs to all your code in the yaws conf file. Do not worry about the forward slashes or back slashes, yaws always gets its way around Paths. For UNIX/LINUX it remains the same e.g. ebin_dir = "/usr/local/lib/erlang/lib/myapp-1.0/ebin".

    However, note that your modules will not be loaded yet until yaws web server fully initialises

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple scenario using Log4net, but it seems that my log
I have created a simple WordPress plugin that automatically sets my new sites up
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created this simple JavaScript code that allows a user to click on
I have created a simple application and edited the index.erb file so that I
I have created a simple JSP file that I want to deploy in Jetty
I have created simple chat application using smack api.i can able to chat well.but
I have created simple web service for my website that generates some json based
I have created simple script: #!/bin/sh column=${1:-1} awk '{colawk='$column'+1; print colawk}' But when I
I have created a simple app for android, that uses buttons to navigate different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.