fsxNet Wiki

BBS Development & Resources

User Tools

Site Tools


tutorials:crystal_bbs:part_two

This is an old revision of the document!


Crystal BBS - Part Two

Negotiating Telnet features with the client

OK, so now we have a basic Telnet hello world example going - let's move forward.

The plan for the tutorial at this stage is to handle feature negotiation in this part, and input on the next one. Haven't decided what to do after that, but probably a state machine interaction post or two, and then you should know most of what it takes to build a basic old-school BBS system. So, on to feature negotiation.

I've been using SyncTerm as my terminal problem for these posts. When connecting to the prototype BBS, I noticed the feature negotiation flow using the “toggle options” telnet client trick from the intro post. We'll focus on those being requested, and not the whole spectrum of options available. IANA has a list of possible options.

Our prototype will:

  • show local echo
  • suppress Go-Ahead
  • ask for the user's terminal type
  • set the connection to binary-mode
  • work out NAWS (Negotiate About Window Size)

All of this will be handled at the start of every connection, so let's revisit our connection handler method:

private def handle_connection(socket)
  socket << "hello world\n"
  socket.close
end

Pretty bare at this moment. Let's start by telling the client we'll be handling feature negotiation. Also, to hold the connection info, let's introduce a new variable in the mix.

private def handle_connection(socket)
  socket << "detecting client features..."
 
  conn = ConnHash.new
 
  socket.close
end

We could write down the whole Crystal type, but since it's cumbersome we'll alias it to a shorter name (in this case, ConnHash). To keep our main file uncluttured, let's move this to a separate file.

module BBS
  alias ConnHash = Hash(Symbol, Bool | String | Int32)
end

Save this in the same folder as main.cr and name it aliases.cr since we'll be adding more aliases to this file as needed. Next, require it on main.cr:

require "./aliases"
tutorials/crystal_bbs/part_two.1491745989.txt.gz · Last modified: 2018/03/29 01:58 (external edit)