Created
August 30, 2009 05:55
-
-
Save JackDanger/177872 to your computer and use it in GitHub Desktop.
simplest possible tcp listener in Erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% NOTE: Do not use this. It's a constantly-evolving testbed for socket experiments | |
%% Use my socket.erl instead | |
-module(listen). | |
-export([start/0]). | |
start() -> | |
application:start(crypto), | |
application:start(ssl), | |
{ok, ListenSocket} = socket:listen(ssl, 56789), | |
socket:send_connections_to_current_process(ListenSocket), | |
io:format("ListenSocket: ~p~n",[ListenSocket]), | |
spawn( | |
fun()-> | |
io:format("About to connect...~n"), | |
{ok, Client} = socket:connect(ssl, "localhost", 56789), | |
io:format("Connected...~n"), | |
socket:send(Client, "here I am\r\n") | |
end | |
), | |
io:format("about to receive~n"), | |
receive | |
{inet_async, ListenPort, _, {ok,ServerSocket}} -> ok | |
end, | |
io:format("ServerSocket: ~p~n",[ServerSocket]), | |
% {ok, NewSocket} = ssl:ssl_accept(ServerSocket,[{keyfile, "server.key"},{certfile, "server.crt"}]), | |
{ok, NewSocket} = socket:to_ssl_server(ServerSocket, [], 5000), | |
io:format("NewSocket: ~p~n",[NewSocket]), | |
socket:close(ListenSocket). | |
% | |
% set_sockopt(ListenSocket, ClientSocket) -> | |
% inet_db:register_socket(ClientSocket, inet_tcp), | |
% prim_inet:setopts( | |
% ClientSocket | |
% prim_inet:getopts(ListenSocket, [active, nodelay, keepalive, delay_send, priority, tos]) | |
% ). | |
% | |
% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment