anchor.diff: +%%
  +%% This is a 'ranch' managed worker. When a socket client
  +%% connects to the server, the socket is passed here and
  +%% we manage the overall communication.
  +%%
  +%% When the client first connects, we challenge for a valid
  +%% message containing the robot's name. If we get a valid-
  +%% looking message, we put a 'registration|robot_name' message
  +%% into the 'registration' tube of beanstalk for processing,
  +%% then we drop into loop that watches the 'robot_name_commands'
  +%% tube and forward them onto the connected socket client.
  +%%
   -module(robot_command_protocol).
   -behavior(ranch_protocol).
   
  
positive.code: 
  loop(command_wait, Socket, Transport, Q, Log, TubeName) ->
    { watching, _ } = beanstalk:watch(Q, io_lib:format("~s_commands", [ TubeName ])),
    case beanstalk:reserve(Q) of
      { reserved, JobId, BMessage } ->
        send_message(Socket, Transport, binary:bin_to_list(BMessage)),
        { deleted } = beanstalk:delete(Q, JobId),
        loop(command_wait, Socket, Transport, Q, Log, TubeName);
      Error ->
        syslog:log(Log, err, "Error reserving a job: ~p",  [ Error ])
    end.
  
  
negative.code:   { ok, Q } = beanstalk:connect(),
    { ok, Log } = syslog:open("robot_command_protocol", [ cons, perror, pid ], local3),
    { using, "registration" } = beanstalk:use(Q, registration),
  
  	loop(init, Socket, Transport, Q, Log, nil),
  
    % If we get here, that means we have dropped out of the socket
    % loop. Close everthing out.
  
  	ok = Transport:close(Socket),
    syslog:close(Log),
    ok = beanstalk:close(Q).
  
  loop(init, Socket, Transport, Q, Log, _) ->
    % Challenge the socket client
    send_message(Socket, Transport, "And You Are?"),
    % Wait for response
    case receive_message(Socket, Transport) of
      { ok, Data } ->
        case string:tokens(Data, "|") of
  