Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:31:46+00:00 2026-06-03T16:31:46+00:00

I have built a very naive parallel ssl acceptor. -module(multiserver). -export([start/0,client/1]). %% This is

  • 0

I have built a very naive parallel ssl acceptor.

-module(multiserver).
-export([start/0,client/1]).

%% This is a dummy SSL Erlang server/client example

start() ->
    spawn_link(fun() -> init([]) end).

init([]) ->
    ssl:start(),
    {ok, ListenSocket} = ssl:listen(9990, [{certfile, "cert.pem"}, {keyfile, "privkey.pem"} ,{reuseaddr, true},{active, true}, binary]),
    Pid = self(),
    spawn_link(fun() -> listener(ListenSocket, Pid, 1) end),
    spawn_link(fun() -> listener(ListenSocket, Pid, 2) end),

    loop().

loop() ->
    receive 
        {new, _Pid} ->
            %% Do stuff here
            loop()
    end.

listener(ListenSocket, Pid, Num) ->
    {ok, ClientSocket} = ssl:transport_accept(ListenSocket),
    ok = ssl:ssl_accept(ClientSocket),
    io:format("listener ~p accepted ~n", [Num]),

    ok = ssl:send(ClientSocket, "server"),
    io:format("listener ~p  sent~n", [Num]),

    receive
        X -> io:format("listener ~p: ~p ~n", [Num, X])
    after 5000 ->
            io:format("listener ~p timeout ~n", [Num]),
            timeout
    end,
    ssl:close(ClientSocket),

    listener(ListenSocket, Pid, Num).

client(Message) ->
    ssl:start(),
    {ok, Socket} = ssl:connect("localhost", 9990,  [binary, {active,true}], infinity),

    receive
        X -> io:format("~p ~n", [X])
    after 2000 ->
            timeout
    end,
    ok = ssl:send(Socket,  Message),    

    ssl:close(Socket),
    io:format("client closed~n").

The probelm I have is that listener 2 does not seem to be able to receive any messages. A sample run of the program looks like this:

First I start the server in shell 1.
Shell 1:

1> multiserver:start().
<0.34.0>

Then I call the client/1 three times from a different shell.
Shell 2:

2> multiserver:client("client").
{ssl,{sslsocket,new_ssl,<0.51.0>},<<"server">>} 
client closed
ok
3> multiserver:client("client").
{ssl,{sslsocket,new_ssl,<0.54.0>},<<"server">>} 
client closed
ok
4> multiserver:client("client").
{ssl,{sslsocket,new_ssl,<0.56.0>},<<"server">>} 
client closed
ok

This is the printouts to server shell.
Shell 1:

listener 1 accepted 
listener 1  sent
listener 1: {ssl,{sslsocket,new_ssl,<0.51.0>},<<"client">>} 
listener 2 accepted 
listener 2  sent
listener 1 accepted 
listener 1  sent
listener 1: {ssl,{sslsocket,new_ssl,<0.54.0>},<<"client">>} 
listener 2 timedout 
2> 

I have spent some hours with this and I cant understand why it is not possible for listener 2 to receive any data. If I edit the code to use gen_tcp it works as expected.
Is there something I am missing?
Is it possible to do this with the current ssl module?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:31:49+00:00Added an answer on June 3, 2026 at 4:31 pm

    The reason for the timeout is that in the second process uses the socket option {active,false}, i.e. the receive will never get any message.

    The erlang docs for the ssl module states that the socket created by calling transport_accept/1 should inherit the options set for the listener socket. The first process inherits the options when it does transport_accept/3, but for some reason the second process doesn’t.
    You can inspect the options with

    ssl:getopts(ClientSocket,[mode, active])
    

    I have no idea why this happens, but a workaround is to explicitly set the options on the newly accepted socket

    ssl:setopts(ClientSocket, [{active,true}, {mode,binary}])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have built custom forms and at this stage are built very well with
I have built a very simple blog application using Ruby on Rails. New to
i built a very basic video player app in Xcode 4.3.2 i have 3
i have built a beautiful website that works very fast in all of the
I have built a very simple internal messaging system inside my application, i want
I am very much an Android newbie and I have built a simple RSS
so I have built my own drag and drop shopping cart(very basic) using Jquery
Please help! I'm still learning so this might be completely wrong. I have built
I have build my very first application to Android and I want now to
I'm trying to build a very simple pure css navigation bar, but have hit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.