Skip to content

Commit

Permalink
initial add
Browse files Browse the repository at this point in the history
  • Loading branch information
davebryson committed Dec 14, 2009
0 parents commit 0141247
Show file tree
Hide file tree
Showing 45 changed files with 7,155 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
@@ -0,0 +1,9 @@
all:
(cd deps/mochiweb/src;$(MAKE))
(cd src;$(MAKE))
(cd examples/basic/src;$(MAKE))

clean:
(cd src;$(MAKE) clean)
(cd deps/mochiweb/src;$(MAKE) clean)
(cd examples/basic/src;$(MAKE) clean)
59 changes: 59 additions & 0 deletions README.textile
@@ -0,0 +1,59 @@
h2. Erlang WebSocket wrapper for "MochiWeb":http://code.google.com/p/mochiweb/

This is a simple wrapper around the mochiweb_socket_server to allow "WebSocket":http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-66 connections. With this wrapper, you can write WebSocket connection loops just like you'd write a normal mochiweb application. Here's an example included with the source code:

<pre>
<code>
-module(basic_websocket).

-export([start/1, stop/0, loop/1]).

start(Options) ->
Loop = fun (WebSocket) ->
?MODULE:loop(WebSocket)
end,
mochiweb_websocket:start([{name, ?MODULE}, {loop, Loop} | Options]).

stop() ->
mochiweb_websocket:stop(?MODULE).


loop(WebSocket) ->
%% Get the data sent from the client
Data = WebSocket:get_data(),

%% For this example...
%% Of course you could handle JSON or another format of your choice
case Data of
%% On initial connect we get this message
"client-connected" ->
WebSocket:send("You are connected!");
%% Other messages go here
Other ->
Msg = "You Said: " ++ Other,
WebSocket:send(Msg)
end.
</code>
</pre>

h3. Requirements:

# Erlang 12.5 or greater
# Google Chrome Browser developer channel release 4.0.249.0


h3. Getting Started:

# download the code
# CD into the erlang_websocket directory
# run make

h3. Run the example:

# CD into the examples/basic directory
# run the 'start.sh' script
# Point the Chrome Browser to 'http://localhost:8000'




9 changes: 9 additions & 0 deletions deps/mochiweb/LICENSE
@@ -0,0 +1,9 @@
This is the MIT license.

Copyright (c) 2007 Mochi Media, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added deps/mochiweb/ebin/.gitignore
Empty file.
20 changes: 20 additions & 0 deletions deps/mochiweb/src/Makefile
@@ -0,0 +1,20 @@
include ../../../support/include.mk

APPLICATION=mochiweb
DOC_OPTS={dir,\"../doc\"}

all: $(EBIN_FILES_NO_DOCS)

debug:
$(MAKE) DEBUG=-DDEBUG

clean:
rm -rf $(EBIN_FILES)

edoc:
$(ERL) -noshell -pa ../ebin \
-eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \
-s init stop

test: all
$(ERL) -noshell -pa ../ebin -s $(APPLICATION) test -s init stop

0 comments on commit 0141247

Please sign in to comment.