Skip to content

Instantly share code, notes, and snippets.

@Vagabond
Last active December 20, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vagabond/dabecf53ac8b4317e51c to your computer and use it in GitHub Desktop.
Save Vagabond/dabecf53ac8b4317e51c to your computer and use it in GitHub Desktop.

R15B01

Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1> c(test).
{ok,test}
2> test:run().
S: Data is [255|<<>>]
C: Data is [255|<<>>]
S: Data is [254|<<>>]
C: Data is [254|<<>>]
ok
3>

R15B02

Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.2  (abort with ^G)
1> c(test).
{ok,test}
2> test:run().
S: Data is [255|<<>>]
C: Data is [255|<<>>]
S: Data is [254]
C: Data is [254]
ok
3>
-module(test).
-export([run/0]).
run() ->
ok = application:start(crypto),
ok = application:start(asn1),
ok = application:start(public_key),
ok = application:start(ssl),
spawn(fun proc_a/0),
proc_b().
proc_a() ->
{ok, LSock} = gen_tcp:listen(1337, [binary, {packet, 4}, {header, 1}, {active, once}, {reuseaddr, true}]),
{ok, Sock} = gen_tcp:accept(LSock),
receive
{tcp, Sock, Data} ->
io:format("S: Data is ~w~n", [Data]),
gen_tcp:send(Sock, <<255:8>>),
{ok, SSLSock} = ssl:ssl_accept(Sock, [{certfile, "priv/certs/cacert.org/ca-cert.pem"}, {keyfile, "priv/certs/cacert.org/ca-key.pem"}, {cacertfile, "priv/certs/cacert.org/ca/root.crt"}]),
ok = ssl:setopts(SSLSock, [{active, once}]),
receive
{ssl, SSLSock, Data2} ->
io:format("S: Data is ~w~n", [Data2]),
ssl:send(SSLSock, <<254:8>>)
end
end.
proc_b() ->
{ok, Sock} = gen_tcp:connect("127.0.0.1", 1337, [binary, {active, once}, {packet, 4}, {header, 1}]),
gen_tcp:send(Sock, <<255:8>>),
receive
{tcp, Sock, Data} ->
io:format("C: Data is ~w~n", [Data]),
{ok, SSLSock} = ssl:connect(Sock, [], 1000),
ssl:send(SSLSock, <<254:8>>),
ok = ssl:setopts(SSLSock, [{active, once}]),
receive
{ssl, SSLSock, Data2} ->
io:format("C: Data is ~w~n", [Data2]),
ok
end
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment