Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to open second socket on same Port #46

Open
geib opened this issue Feb 5, 2021 · 1 comment
Open

unable to open second socket on same Port #46

geib opened this issue Feb 5, 2021 · 1 comment

Comments

@geib
Copy link

geib commented Feb 5, 2021

I am working on an app which must join multiple source-specific multicasts, SSM, and all the multicasts use the same group address and port. Only the source address changes. I have tested and this works fine if the group and port are different for each multicast. I have a function:

open_ssm_mc(Group, Port, Source, Interface) ->
    % add_source_membership

    LocalIp = ip_to_binary(Interface),
    GroupIp = ip_to_binary(Group),
    SourceIp = ip_to_binary(Source),
    Bin = << GroupIp/binary, LocalIp/binary, SourceIp/binary >>,

    {ok, Fd} = procket:open(Port, [{protocol, udp}, {type, dgram}, {family, inet}]),
    ok = procket:setsockopt(Fd, 'SOL_SOCKET', 'SO_REUSEADDR',  <<1:32>>),
    ok = procket:setsockopt(Fd, 'SOL_SOCKET', 'SO_REUSEPORT',  <<1:32>>),
    ok = procket:setsockopt(Fd, 0, 39,  Bin),
    % ok = procket:bind(Fd, GroupIp),

    {ok, Fd, Port}.

Where the returned FD is then used in a gen_udp:open() like:

{ok, Fd, Port} = cse_socket:open_ssm_mc(Addr, Port, Source, LAddr),
{ok, Socket} = gen_udp:open(0, [{fd, Fd}, binary, {active, true}, {recbuf, RecBuf}, {buffer, Buffer}, {read_packets, ReadPackets}]),
?LOGIT_INFO("SSM socket open and active", [{fd, Fd}, {socket, Socket}, {port, Port}, {group, Addr}, {source, Source}, {interface, LAddr}])

As I said, only the "Source" changes for each instance, and the second instance fails with {error,eaddrinuse} on the procket:open(Port...) call. I am missing some other option that needs set on the FD, or Socket.??

Thanks,
Mark.

@msantos
Copy link
Owner

msantos commented May 30, 2021

@geib Sorry for the delay, didn't get the notification for this issue!

Some hints on debugging:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants