Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(test).
- -export([start/2]).
- start(Address, Port) ->
- OP = [
- inet,
- binary,
- {reuseaddr, true},
- {nodelay, true}
- ],
- Request = ["GET / HTTP/1.1\r\nHost: ", Address, "\r\n\r\n"],
- io:format("~p~n", [list_to_binary(Request)]),
- {ok, Socket} = gen_tcp:connect(Address, Port, OP, 5000),
- ok = gen_tcp:send(Socket, list_to_binary(Request)),
- getdata(Socket, []).
- getdata(Socket, D) ->
- io:format("receive data...~n", []),
- receive
- {tcp,Socket, Data} ->
- getdata(Socket, [Data | D]);
- {tcp_closed, Socket} ->
- io:format("tcp_closed~n", []),
- lists:reverse(D);
- {tcp_error, Socket, _Reason} ->
- io:format("tcp_error~n", []),
- lists:reverse(D)
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement