云端接口socket通信测试
bin.shen
2016-11-30 e226769d1d70fa6186dac0dca69e5c1b5d7a2ca2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%%%-------------------------------------------------------------------
%%% @author bin.shen
%%% @copyright (C) 2016, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 29. Nov 2016 6:30 AM
%%%-------------------------------------------------------------------
-module(handler).
-author("bin.shen").
 
%% API
-export([doWork/3]).
-import(tcp_server, [loop/3]).
 
doWork(Socket, Data, Count) ->
 
  TotalLen = byte_size(Data),
%%  io:format("count ~p~n", [TotalLen]),
 
  if
    TotalLen < 12 ->
      loop(Socket, Data, Count);
 
    true ->
      <<Head:6/binary, Rest/binary>> = Data,
      Len = byte_size(Rest),
 
      case Head of
        <<90, 0, 16, 1, 0, 1>> ->
          if
            Len =:= 6 ->
%%              <<D1, D2, D3, D4, D5, D6>> = Rest,
%%              io:format("~p~n", [<<90, 0, 16, 1, 0, 1, D1, D2, D3, D4, D5, D6>>]),
              loop(Socket, <<>>, Count+1);
 
            Len > 6 ->
              <<_:6/binary, B/binary>> = Rest,
%%              <<D1, D2, D3, D4, D5, D6>> = A,
%%              io:format("~p~n", [<<90, 0, 16, 1, 0, 1, D1, D2, D3, D4, D5, D6>>]),
              doWork(Socket, B, Count+1);
 
            true ->
              loop(Socket, Data, Count)
          end;
 
        <<90, 0, 16, 1, 0, 2>> ->
          io:format("xxxxxxxxxxxxxxxxxxxx\n");
 
        true ->
          io:format("yyyyyyyyyyyyyyyyyyyy\n")
      end
  end.
 
 
 
%%  io:format("recv ~w~n", [Head]),
%%  io:format("recv ~w~n", [Rest]).