Browse Source

n2o_relay to n4u_relay

221V 3 years ago
parent
commit
2484c4ec98
3 changed files with 32 additions and 21 deletions
  1. 1 1
      ebin/n4u.app
  2. 0 20
      src/endpoints/n2o_relay.erl
  3. 31 0
      src/endpoints/n4u_relay.erl

+ 1 - 1
ebin/n4u.app

@@ -2,7 +2,7 @@
   {description, "N4U WebSocket Application Server"},
   {description, "N4U WebSocket Application Server"},
   {vsn, "4.4.20"},
   {vsn, "4.4.20"},
   {applications, [kernel, stdlib, asn1, public_key, ssl, crypto, ranch, cowboy, fs, active, sh, gproc, nitro]},
   {applications, [kernel, stdlib, asn1, public_key, ssl, crypto, ranch, cowboy, fs, active, sh, gproc, nitro]},
-  {modules, [n2o, n4u_app, n4u_sup, n4u_async, n2o_xhr, n4u_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n4u_document, n2o_proto, n2o_relay, n4u_error, n4u_io, n4u_log, n4u_mq, n4u_pickle, n4u_query, n4u_secret, n4u_session, n4u_syn, n4u_client, n4u_file, n4u_heart, n4u_http, n4u_nitrogen, n4u_text, wf, wf_convert, wf_utils]},
+  {modules, [n2o, n4u_app, n4u_sup, n4u_async, n2o_xhr, n4u_cx, n2o_cowboy, n2o_multipart, n2o_static, n2o_stream, n4u_document, n2o_proto, n4u_relay, n4u_error, n4u_io, n4u_log, n4u_mq, n4u_pickle, n4u_query, n4u_secret, n4u_session, n4u_syn, n4u_client, n4u_file, n4u_heart, n4u_http, n4u_nitrogen, n4u_text, wf, wf_convert, wf_utils]},
   {registered, [n4u_sup]},
   {registered, [n4u_sup]},
   {mod, {n4u_app, []}},
   {mod, {n4u_app, []}},
   {env, []}
   {env, []}

+ 0 - 20
src/endpoints/n2o_relay.erl

@@ -1,20 +0,0 @@
--module(n2o_relay).
--description('N4U TCP relay endpoint handler').
--compile([export_all, nowarn_export_all]).
-
-connect(IP, PortNo) ->
-    {ok, Socket} = gen_tcp:connect(IP, PortNo, [{active, false}, {packet, 2}]),
-    spawn(fun() -> recv(Socket) end),
-    Socket.
-
-send(Socket, Message) ->
-    BinMsg = term_to_binary(Message),
-    gen_tcp:send(Socket, BinMsg).
-
-recv(Socket) ->
-    {ok, A} = gen_tcp:recv(Socket, 0),
-    io:format("Received: ~p~n", [A]),
-    recv(Socket).
-
-disconnect(Socket) ->
-    gen_tcp:close(Socket).

+ 31 - 0
src/endpoints/n4u_relay.erl

@@ -0,0 +1,31 @@
+-module(n4u_relay).
+
+-export([connect/2, send/2, recv/1, disconnect/1]).
+% todo check where/how used
+
+
+% N4U TCP relay endpoint handler
+
+connect(IP, PortNo) ->
+  {ok, Socket} = gen_tcp:connect(IP, PortNo, [{active, false}, {packet, 2}]),
+  erlang:spawn(
+    fun() ->
+      recv(Socket)
+    end),
+  Socket.
+
+
+send(Socket, Message) ->
+  BinMsg = erlang:term_to_binary(Message),
+  gen_tcp:send(Socket, BinMsg).
+
+
+recv(Socket) ->
+  {ok, A} = gen_tcp:recv(Socket, 0),
+  wf:info(?MODULE, "Received: ~p~n", [A]),
+  recv(Socket).
+
+
+disconnect(Socket) ->
+  gen_tcp:close(Socket).
+