Skip to content

Commit

Permalink
Merge pull request joewalnes#257 from brickcap/master
Browse files Browse the repository at this point in the history
updated with examples of lua
  • Loading branch information
asergeyev committed May 8, 2017
2 parents 6b0f674 + 8a582a8 commit 015d90b
Show file tree
Hide file tree
Showing 4 changed files with 439 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/lua/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
The examples demonstrate the use of websocketd with lua. There are two examples in the directory both very basic.

1. Greeter.lua simply echos back any input made from the client
2. json_ws.lua echos back any input from the client *after* converting it into a json string

It is pretty simple to extend these examples into full fledged applications. All you need is an stdin input loop

```
local input = io.stdin:read()
while input do
-- do anything here
-- update the input
input = io.stdin:read()
end
```

any thing you `print` goes out to the websocket client

Libraries and third party modules can be used by the standard `require` statement in lua.

## Running the examples



##### 1. Download

[Install](https://github.com/joewalnes/websocketd/wiki/Download-and-install) websocketd and add it to your `PATH`.

##### 2. Start a server: greeter

Run `websocketd --port=8080 --devconsole lua ./greeter.lua` and then go to `http://localhost:8080` to interact with it

##### 3. Start a server: json_ws

Run `websocketd --port=8080 --devconsole lua ./json_ws.lua` and then go to `http://localhost:8080` to interact with it

If you are using luajit instead of lua you may run the examples like this
(this assumes that you've got luajit in your path)

`websocketd --port=8080 --devconsole luajit ./json_ws.lua` and then go to `http://localhost:8080`
7 changes: 7 additions & 0 deletions examples/lua/greeter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local input = io.stdin:read()
while input do
print(input)
io.stdout:flush()
input = io.stdin:read()
end

Loading

0 comments on commit 015d90b

Please sign in to comment.