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 8220841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:41:02+00:00 2026-06-07T13:41:02+00:00

Hi all, Very new to Erlang, coming from C/C++/Java. Been playing with code and

  • 0

Hi all,

Very new to Erlang, coming from C/C++/Java. Been playing with code and have myself narrowed to a point where a second of guidance might save me a half a day. So what I have is a little telnet client which I’m intending to connect to a freeswitch esl port and let me issue commands to the port as I would in fs_cli. (I guess the main thing is…I’m trying to talk to a port that I should be able to communicate via telnet). The erlang app fails while a Linux telnet is working great. I’m sure the issue is simple and subtle; any help appreciated!

So, here’s how the session goes using Linux telnet:

$>telnet localhost 8021  
Trying localhost...  
Connected to localhost.  
Escape character is '^]'.  
Content-Type: auth/request  

auth password<ENTER>  
<ENTER>  
Content-Type: command/reply  
Reply-Text: +OK accepted  

log 1<ENTER>  
<ENTER>  
Content-Type: command/reply  
Reply-Text: +OK log level 1 [1]   

…Okay, here’s my telnet client code:

-module(getty).  
-export([s/0]).  

%-define(LISTEN_PORT, 9000).  
%-define(TCP_OPTS, [binary, {packet, raw}, {nodelay, true}, {reuseaddr, true}, {active, once}]).  

s() ->  
    case gen_tcp:connect( "localhost", 8021,[{active,false},{packet,2}]) of  
        {ok,Sock} ->   
            io:format("~p Connected to localhost 8021.~n", [erlang:localtime()] ),
            main_loop( Sock );  

        Error ->
             io:format("Error: ~p~n", [Error]) 
    end.

 main_loop( Sock ) ->
     Command = get_user_input( "Command> " ),

     spawn(fun() -> ex_cmd( Sock, Command ) end),
     main_loop( Sock ).

 ex_cmd(Sock, Command) ->
     B = gen_tcp:recv( Sock, 0 ),
    io:format( "Response: ~p~n", [B] ),
    gen_tcp:send( Sock, Command ),
    A = gen_tcp:recv( Sock, 0 ),
    %gen_tcp:close( Sock ),
    io:format( "Response: ~p~n", [A] ).     

get_user_input( Prompt ) ->
    A1 = string:concat(
        string:strip( % remove spaces from front and back
            string:strip( % remove line-feed from the end
                io:get_line( Prompt ), right, $\n)), "\r\n\r\n" ),
    io:format( "Command is: ~p~n", [A1] ),
    A1.

…here’s a run of using the erlang client:

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

Eshell V5.9.1  (abort with ^G)  
1> c(getty).  
{ok,getty}  
2> getty:s().  
{{2012,7,12},{10,15,0}} Connected to localhost 8021.  
Command> auth password  
Command is: "auth password\r\n\r\n"  
Response: {error,closed}  
Response: {error,closed}  
Command>   

Any clues on the different result using the erlang client? TIA!

  • 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-07T13:41:04+00:00Added an answer on June 7, 2026 at 1:41 pm

    By using {packet,2}, you’re claiming that packets will be sent with a 2-byte header declaring the size of the packet, and that you’re expecting the server to send such headers as well. Telnet does not do this, so if you’re trying to emulate a telnet client, don’t specify a packet mode of 2. Instead, use 0 or raw for the packet type to specify no header. I believe that leaving off the packet option defaults to no header as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im very new to all coding including jquery. I though this would have been
All, I am very new to MVC3 / jQuery combo and have been reading
I'm very new to programming in Android, but have been struggling all day with
First of all, let me say I am very new to rails, have been
I am a very new beginner and have been reading the help forums. All
Hello all! I am very new to xcode and objective-c but I have been
I'm very new with rails and I've been building a CMS application backend. All
I'm very new to JQuery and don't have much experience with javascript at all,
I have a small problem and since I am very new to all this
I'm very new to web-development (I feel like all my posts lately have started

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.