Erlang listen port

classic Classic list List threaded Threaded
6 messages Options
shk
Reply | Threaded
Open this post in threaded view
|

Erlang listen port

shk
Hello,

I write simple pop3 server. I try to listen 110 port:

-module(test).

-export([listen/1]).

-define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]).

% Call echo:listen(Port) to start the service.
listen(Port) ->
    case  gen_tcp:listen(Port, ?TCP_OPTIONS) of
    {ok, LSocket} ->
       accept(LSocket);
    {error, Reason} ->
            Reason
    end.
   
% Wait for incoming connections and spawn the echo loop when we get one.
accept(LSocket) ->
    {ok, Socket} = gen_tcp:accept(LSocket),
    spawn(fun() -> loop(Socket) end),
    accept(LSocket).

% Echo back whatever data we receive on Socket.
loop(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Data} ->
            gen_tcp:send(Socket, Data),
            loop(Socket);
        {error, closed} ->
            ok
    end.

I run this code in eshell:
1>test:listen(110).
eacces

What's wrong?

Thank you.
shk
Reply | Threaded
Open this post in threaded view
|

Re: Erlang listen port

shk
I try run it under root and it's work! How can i make that it works under user, without root.
Reply | Threaded
Open this post in threaded view
|

Re: Erlang listen port

Andrew Tunnell-Jones
On 16/01/2011, at 5:02 PM, shk wrote:

>
> I try run it under root and it's work! How can i make that it works under
> user, without root.
>

Although geared towards yaws, this page covers all of the options for binding to a privileged port that I'm aware of:

http://yaws.hyber.org/privbind.yaws

— Andrew
http://andrew.tj.id.au/
________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Erlang listen port

Abdul Fattah Mahran
In reply to this post by shk
Hi all,
    The problem is you are using a reserved port.

Thanks

On Sun, Jan 16, 2011 at 7:59 AM, shk <[hidden email]> wrote:

>
> Hello,
>
> I write simple pop3 server. I try to listen 110 port:
>
> -module(test).
>
> -export([listen/1]).
>
> -define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr,
> true}]).
>
> % Call echo:listen(Port) to start the service.
> listen(Port) ->
>    case  gen_tcp:listen(Port, ?TCP_OPTIONS) of
>    {ok, LSocket} ->
>       accept(LSocket);
>    {error, Reason} ->
>            Reason
>    end.
>
> % Wait for incoming connections and spawn the echo loop when we get one.
> accept(LSocket) ->
>    {ok, Socket} = gen_tcp:accept(LSocket),
>    spawn(fun() -> loop(Socket) end),
>    accept(LSocket).
>
> % Echo back whatever data we receive on Socket.
> loop(Socket) ->
>    case gen_tcp:recv(Socket, 0) of
>        {ok, Data} ->
>            gen_tcp:send(Socket, Data),
>            loop(Socket);
>        {error, closed} ->
>            ok
>    end.
>
> I run this code in eshell:
> 1>test:listen(110).
> eacces
>
> What's wrong?
>
> Thank you.
>
> --
> View this message in context:
> http://erlang.2086793.n4.nabble.com/Erlang-listen-port-tp3219753p3219753.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>


--
Thanks
Best Regards,
Abd El-Fattah Mahran
Reply | Threaded
Open this post in threaded view
|

Re: Erlang listen port

Alain O'Dea
In reply to this post by Andrew Tunnell-Jones
On 2011-01-16, at 2:52, Andrew Tunnell-Jones <[hidden email]> wrote:

> On 16/01/2011, at 5:02 PM, shk wrote:
>
>>
>> I try run it under root and it's work! How can i make that it works under
>> user, without root.
>>
>
> Although geared towards yaws, this page covers all of the options for binding to a privileged port that I'm aware of:
>
> http://yaws.hyber.org/privbind.yaws

Thank you Andrew.  That Yaws article is generally applicable for binding privileged ports in any program.

I like the idea of using authbind or privbind for running Zotonic on 80
or 443.  Unfortunately I got inpatient and fell back on NAT pre-routing with iptables (which I learned when setting up TeamCity).  I'm going to give authbind and privbind another shot.

Thanks again,
Alain

>
> — Andrew
> http://andrew.tj.id.au/

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Erlang listen port

Brujo Benavides-2
You may need to use something like fdsrv.  Using jungerl sources, I've
created a project on github with that:
http://github.com/elbrujohalcon/fd_server

On Sun, Jan 16, 2011 at 12:00 PM, Alain O'Dea <[hidden email]> wrote:

> On 2011-01-16, at 2:52, Andrew Tunnell-Jones <[hidden email]> wrote:
>
> > On 16/01/2011, at 5:02 PM, shk wrote:
> >
> >>
> >> I try run it under root and it's work! How can i make that it works
> under
> >> user, without root.
> >>
> >
> > Although geared towards yaws, this page covers all of the options for
> binding to a privileged port that I'm aware of:
> >
> > http://yaws.hyber.org/privbind.yaws
>
> Thank you Andrew.  That Yaws article is generally applicable for binding
> privileged ports in any program.
>
> I like the idea of using authbind or privbind for running Zotonic on 80
> or 443.  Unfortunately I got inpatient and fell back on NAT pre-routing
> with iptables (which I learned when setting up TeamCity).  I'm going to give
> authbind and privbind another shot.
>
> Thanks again,
> Alain
>
> >
> > — Andrew
> > http://andrew.tj.id.au/
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:[hidden email]
>
>