YAWS Websocket Trouble - erlang

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)?

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).

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.

Related

How to install Ngrok 2.0 on linux subsystem on Windows 10

I am trying to use Ngrok to create an introspected tunnel to localhost webhook development tool on my Linux subsystem (Powershell --> bash)
I try to install ngrok using the following:
sudo apt install ngrok-client
From what I understand the sudo command used installs ngrok v 1.6.
When I attempt to execute ngrok 80 I get an error:
Invalid address server_addr 'ngrokd.ngrok.com:443'
I searched for this in another post and was informed that ngrok v. 1.6 is obsolete and in order to continue using ngrok would be to upgrade to 2.0
Testing PayPal with Rails
It's advised to download from the website http://ngrok.com, which is simple enough, but what is the correct way to download for linux subsystem use? Should I download for Linux and unzip? Or am I suppose to download for Windows?
Let me know if I'm misunderstanding anything
I use ubuntu since years, I trust the online instructions so either do:
sudo apt-get update
sudo apt-get install ngrok-client
or try to use this instruction and let me know if you have problems
the same instructions are included hear
$ unzip /path/to/ngrok.zip
$ is just the sign from your terminal. You do not need to input $, but you need to open the terminal (ctrl+alt+t), run the unzip command to unzip the folder.
You will find the folder under your downloads. So / is the root of your machine. You need to go inside your home folder which will be /home so you do cd (change directory) followed by that path
cd /home
then you do ls to list all the directories. You should see your profile with your name username. You should be able to get in the download folder with cd <username>/Downloads where <username> should be replaced with your personal folder name
At this point you are inside the Downloads directory. You can do an ls in your terminal, find the name of the file you downloaded (should be something like ngrok-stable-linux-amd64.zip) and run
unzip <file-name.zip>
where file name is the file you downloaded (something like ngrok-stable-linux-amd64.zip) or you can go back to the root directory and run
cd /
unzip /home/<username>/Downloads/<yourfile.zip>
Read the documentation on how to use ngrok. Try it out by running it from the command line:
./ngrok help
Also I read from the documentation, that you can set up that address
There is some discussion online about this
Testing PayPal with Rails
I can help you more but I need your feedback
You can try this from the official docs.
sudo tar xvzf ~/Downloads/ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin

Upload XML file to server on another machine

How can I upload a XML file that resides on a computer (let's call it workstation) onto a BaseX server that runs on another computer (server)?
To upload a XML file to the BaseX server on workstation I use
basexclient -n localhost -d -w -c "CREATE DATABASE ${db_name} ${file}"
When the hostname is changed from localhost to server, this command fails with
org.basex.core.BaseXException: Resource "[complete FILE path]" not found.
IIUC, the error happens because this command does not upload the XML file itself, but just asks the server to read it from the path ${file}. The command then fails because ${file} is not available on server but only on workstation.
What command should I use to upload the XML file to the remote server?
(Obviously without copying the file to the server and then executing the command locally on the server.)
Assuming that -n means what you seem to be using it to mean, and that a local client can in fact communicate with a remote server, and assuming also that your XML document is a standalone document, I'd try something like the following (not tested), with $server, $dbname, $file, and $baseurl defined as environment variables:
(echo CREATE DATABASE ${dbname};
echo ADD TO ${baseurl};
cat ${file};
echo EXIT ) | basexclient -n myserver -d -w
But otherwise I'd use the BaseX HTTP server and use curl or wget to sent a PUT request with the file to the address http://myserver.example.org:8984/webdav/mydb/myfile.xml (and of course, if necessary, I'd use curl multiple times to make the database and then add data to it).

Making Fedena a Windows Service Failed

I successfully installed Fedena on Windows using this tutorial:
http://en.wikibooks.org/wiki/Fedena/Installation
The problem is that each time I start windows, I need to run the command ruby script/server so that I can access the project locally. I tried making Fedena a Windows Service that starts automatically by following the steps mentioned in the tutorial, but it seems that it didn't work.
Making a Windows Service
If you want to run Fedena as a Windows Service (which automatically starts), do the following commands:
Open the Ruby Command prompt and go to your Fedena Installation director //do they mean by this C:/Fedena?
Install a Gem:
gem install win32-service
Install a Gem:
gem install mongrel_service
Run the command:
mongrel_rails service::install -N Fedena -c C:\FEDENA -p 3001 -e production
(Replace C:\FEDENA with whatever your Fedena installation Directory is.) You may also wish to change the port from 3001 to 80 so when entering the address from other computers, it is not required that you enter a port.
Go to windows search at the start menu, type:
services.msc
Look for service named 'Fedena' and set it to automatic
Restart your computer and see if the fedena start automatically. Always make sure that your server is running.
Any ideas what could be the problem?
Right after Fedena is configured, the start of the application is via console which should stay open for all the times if we want the application to be up and running. But quite often will get closed (human error, server down etc) and the application will go down.
The same applies if the server is rebooted/bounced and all over again.
So here is the solution if you don't want to go over this hassle:
Download http://nssm.cc/download/?page=download
Unpack it (lets say C:\NSSM)
Create a batch file ( lets say C:\Fedena\StartFedena.bat)
Edit the batch file ( right click on the bat file and click Edit)
Past the following code (change the paths accordingly)
********************************** (without the stars and this comment)
cd \
cd Fedena
mongrel_rails start -e production
Note: If you want to start it as development mode remove -e production from the last line
Open CMD
Type cd\
Type cd NSSM
depending on the system type: "cd win32" ot "cd win64"
9.Type in the cmd : "nssm install"
A modal window will pop-up
Click Browse
Navigate to the location where the batch file is and select it;
Leave options empty
Service name "Fedena"
Install Service
Go to "Services" (usually under Control Panel\System and Security\Administrative Tools)
Start Services
You should find service named "Fedena"
Start Service
Navigate to http://example.com:3000 and Fedena should be up
The service should be already set as automatic so if the server is restarted Fedena will come up automatically.
If you need to bounce the application just restart the Fedena Service.
That is,
Thank you

Pow server: serving local rails app via myapp.dev.com domain

Pow server is working fine with .dev domains on my local machine (OS X Lion). So myapp.dev is all good.
I now would like to make it serve myapp.dev.com (and myapp.dev.fr, and myapp.dev.XX) so myapp will serve the localized version, which is internally determined via the top-level-domain requesting: .com for english, fr for french ... and so on.
what i did so far: setting .powconfig to
export POW_DOMAINS=dev,dev.com,dev.fr
export POW_EXT_DOMAINS=dev.com,dev.fr
and then, of course, un- and reinstalling pow.
what i get so far when calling myapp.dev.com is just the regular apache view. pow doesnt serve my request... instead it sends it to apache and apache shows just all my folders in my server root...
any ideas?
My solution:
...simple as that...
follow this wiki https://github.com/37signals/pow/wiki/Running-Pow-with-Apache (step 3 is the important one)
then of course create/modify .powconfig to contain this line
export POW_DOMAINS=dev,dev.com,dev.fr
finally make pow "aware" of this new setup via de- and reinstalling it
curl get.pow.cx/uninstall.sh | sh
curl get.pow.cx | sh
and as a last step: restart apache
sudo apachectl restart

Erlang install: "Can't find config file " error message

I'm trying to install Yaws on my Ubuntu 11.01 system via apt-get install yaws. But when I call the shell script yaws from the command line I get the following error: Yaws: Bad conf: "Can't find config file "
Unless my aging eyes are missing something, I can't find enlightenment in either the Yaws website or Zachery Kessin's book.
I can find configuration files in /etc/yaws. But is there something else I need to know/do?
Thanks,
LRP
If you installed yaws with the package manager then it's controlled by an init script (and you should work with that instead of running yaws manually, I'll add).
You're most likely running yaws as a non-privileged user, and if you look closely, the directory /etc/yaws is:
drwxr-x--- 4 root yaws 4096 Aug 7 10:36 yaws
You're probably trying to run yaws under a user other than root, and without membership in the yaws group.
I would venture a guess that this is a bug in the distro's packaging rather than in yaws since the man page clearly states that running it as a non-privileged user it falls back to reading /etc/yaws/yaws.conf, except that under Debian/Ubuntu (I'm on Debian 6) the permissions on /etc/yaws/ do not live up to the claim in the map page.
But, if you work through the distro's init script and daemon management facilities your problem goes away magically. That I think is preferable to tapping the Debian packager on the shoulder and having a long conversation about config directory permissions. :)
Try doing the following.
$ touch yaws.conf
$ yaws
Hit the enter key to bring up the prompt. Works on Debian 7 (wheezy).
You may also want to do the following to place your username in the yaws group.
$ adduser USERNAME yaws
To one of the maintainers of this package found in the readme file, I have pointed them to here.
$ dpkg -L yaws | grep -i readme
My system is Debian 7 or often called wheezy distro. It's actually kali-linux but that's just fyi stuff. I browsed to /etc/yaws as root with nautilus otherwise it's locked.
~$ sudo su
[sudo] password for username:
# nautilus
Initializing nautilus-gdu extension
Now you may look in the /etc/yaws directory.
The yaws.conf should be in there. Josef would be correct as this is what yaws will try to use if the user has access to this file. But not being root you don't.
My solution is to just get ideas out of that file and the others within the same directory. Take this next answer from Van and make your home/user have a yaws.conf and play around with different configurations from what you found in the etc one. Not that hard to copy and paste if you just have access to the files. Enjoy! :-D

Resources