Skip to content

Commit 2b2a1c1

Browse files
Update README.md
1 parent 1c6e94b commit 2b2a1c1

File tree

1 file changed

+0
-98
lines changed

1 file changed

+0
-98
lines changed

README.md

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,104 +16,6 @@ Clients are available in three different flavours:
1616
- coroutine based ([copas](http://keplerproject.github.com/copas))
1717
- asynchronous ([lua-ev](https://github.com/brimworks/lua-ev))
1818

19-
Servers are available as two different flavours:
20-
21-
- coroutine based ([copas](http://keplerproject.github.com/copas))
22-
- asynchronous ([lua-ev](https://github.com/brimworks/lua-ev))
23-
24-
25-
A webserver is NOT part of lua-websockets. If you are looking for a feature rich webserver framework, have a look at [orbit](http://keplerproject.github.com/orbit/) or others. It is no problem to work with a "normal" webserver and lua-websockets side by side (two processes, different ports), since websockets are not subject of the 'Same origin policy'.
26-
27-
# Usage
28-
## copas echo server
29-
This implements a basic echo server via Websockets protocol. Once you are connected with the server, all messages you send will be returned ('echoed') by the server immediately.
30-
31-
```lua
32-
local copas = require'copas'
33-
34-
-- create a copas webserver and start listening
35-
local server = require'websocket'.server.copas.listen
36-
{
37-
-- listen on port 8080
38-
port = 8080,
39-
-- the protocols field holds
40-
-- key: protocol name
41-
-- value: callback on new connection
42-
protocols = {
43-
-- this callback is called, whenever a new client connects.
44-
-- ws is a new websocket instance
45-
echo = function(ws)
46-
while true do
47-
local message = ws:receive()
48-
if message then
49-
ws:send(message)
50-
else
51-
ws:close()
52-
return
53-
end
54-
end
55-
end
56-
}
57-
}
58-
59-
-- use the copas loop
60-
copas.loop()
61-
```
62-
63-
## lua-ev echo server
64-
This implements a basic echo server via Websockets protocol. Once you are connected with the server, all messages you send will be returned ('echoed') by the server immediately.
65-
66-
```lua
67-
local ev = require'ev'
68-
69-
-- create a copas webserver and start listening
70-
local server = require'websocket'.server.ev.listen
71-
{
72-
-- listen on port 8080
73-
port = 8080,
74-
-- the protocols field holds
75-
-- key: protocol name
76-
-- value: callback on new connection
77-
protocols = {
78-
-- this callback is called, whenever a new client connects.
79-
-- ws is a new websocket instance
80-
echo = function(ws)
81-
ws:on_message(function(ws,message)
82-
ws:send(message)
83-
end)
84-
85-
-- this is optional
86-
ws:on_close(function()
87-
ws:close()
88-
end)
89-
end
90-
}
91-
}
92-
93-
-- use the lua-ev loop
94-
ev.Loop.default:loop()
95-
96-
```
97-
98-
## Running test-server examples
99-
100-
The folder test-server contains two re-implementations of the [libwebsocket](http://git.warmcat.com/cgi-bin/cgit/libwebsockets/) test-server.c example.
101-
102-
```shell
103-
cd test-server
104-
lua test-server-ev.lua
105-
```
106-
107-
```shell
108-
cd test-server
109-
lua test-server-copas.lua
110-
```
111-
112-
Connect to the from Javascript (e.g. chrome's debugging console) like this:
113-
```Javascript
114-
var echoWs = new WebSocket('ws://127.0.0.1:8002','echo');
115-
```
116-
11719
# Dependencies
11820

11921
The client and server modules depend on:

0 commit comments

Comments
 (0)