Skip to content

Commit 9b7db58

Browse files
author
HpyHacking
committed
add webtekcos behaviour
1 parent 5598b83 commit 9b7db58

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

examples/server.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ main(_) ->
99
application:start(sasl),
1010
application:start(webtekcos),
1111

12+
webtekcos_event_logger:add_handler(),
13+
1214
io:format("Open client.html test websocket server.~n"),
1315
io:format("It's listen on localhost:3008.~n"),
1416
io:format("Press Ctrl+C to shutdown server!!!~n"),

src/webtekcos.erl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-module(webtekcos).
22
-export([start_link/0, start_link/2, start_link/3, stop/1, loop/1]).
33
-export([send_data/1, send_data/2, close/0]).
4+
-export([behaviour_info/1]).
45

56
start_link() ->
67
start_link(?MODULE, "127.0.0.1", 3008).
@@ -15,6 +16,15 @@ start_link(Name, Host, Port) when is_list(Host), is_integer(Port) ->
1516
stop(Name) ->
1617
mochiweb_socket_server:stop(Name).
1718

19+
behaviour_info(callbacks) ->
20+
[{connect, 0},
21+
{disconnect, 1},
22+
{handle_message, 2},
23+
{handle_data, 2}];
24+
25+
behaviour_info(_Other) ->
26+
undefined.
27+
1828
%%%
1929
%%% websocket protocol
2030
%%%

src/webtekcos_sample_handler.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-module(webtekcos_sample_handler).
2+
-behaviour(webtekcos).
23
-export([connect/0, disconnect/1, handle_data/2, handle_message/2]).
34

45
connect() ->
@@ -22,5 +23,4 @@ handle_data(Data, {counter, Counter}) ->
2223

2324
handle_message({timeout, _, ?MODULE}, LoopData) ->
2425
webtekcos:send_data(list_to_binary("Hello Timer")),
25-
io:format("<<<<< ~p~n", ["Hello Timer"]),
2626
LoopData.

0 commit comments

Comments
 (0)