anchor.diff:              ?TRACE("~.0p Sent message ~.0p~n",
                      [pid_groups:my_pidname(), Message]),
               ?LOG_MESSAGE_SOCK('send', Message, byte_size(BinaryMessage), channel(State)),
  -            State;
  +            set_number_of_timeouts(State, 0);
           {error, closed} ->
               Address = dest_ip(State),
               Port = dest_port(State),
               report_bundle_error(Options, {Address, Port, Pid}, Message,
                                   socket_closed),
               log:log(warn,"[ CC ~p ] sending closed connection", [self()]),
  -            close_connection(Socket, State);
  +            close_connection(Socket, set_number_of_timeouts(State, 0));
           {error, timeout} ->
  -            log:log(error,"[ CC ~p ] couldn't send to ~.0p:~.0p (~.0p). retrying.",
  -                    [self(), dest_ip(State), dest_port(State), timeout]),
  -            send_internal(Pid, Message, Options, BinaryMessage, State);
  +            NumberOfTimeouts = number_of_timeouts(State),
  +            if  % retry 5 times
  +                NumberOfTimeouts < 5 ->
  +                    log:log(error,"[ CC ~p ] couldn't send to ~.0p:~.0p (~.0p). retrying.",
  +                            [self(), dest_ip(State), dest_port(State), timeout]),
  +                    send_internal(Pid, Message, Options, BinaryMessage, set_number_of_timeouts(State, NumberOfTimeouts + 1));
  +                true ->
  +                    log:log(error,"[ CC ~p ] couldn't send to ~.0p:~.0p (~.0p). retried 5 times, now closing the connection.",
  +                            [self(), dest_ip(State), dest_port(State), timeout]),
  +                    Address = dest_ip(State),
  +                    Port = dest_port(State),
  +                    report_bundle_error(Options, {Address, Port, Pid}, Message,
  +                                        socket_timeout),
  +                    close_connection(Socket, set_number_of_timeouts(State, 0))
  +            end;
           {error, Reason} ->
               Address = dest_ip(State),
               Port = dest_port(State),
  
positive.code:                                 Reason),
              log:log(error,"[ CC ~p ] couldn't send to ~.0p:~.0p (~.0p). closing connection",
                      [self(), Address, Port, Reason]),
              close_connection(Socket, State)
      end.
  
  -spec new_connection(inet:ip_address(), comm_server:tcp_port(),
  
negative.code: last_stat_report(State)          -> element(13, State).
  -spec set_last_stat_report(state(), stat_report()) -> state().
  set_last_stat_report(State, Val) -> setelement(13, State, Val).
  
  -spec number_of_timeouts(state()) -> non_neg_integer().
  number_of_timeouts(State) -> element(14, State).
  -spec set_number_of_timeouts(state(), non_neg_integer()) -> state().
  set_number_of_timeouts(State, N) -> setelement(14, State, N).
  
  -spec status(State::state()) -> notconnected | connected.
  status(State) ->
  