anchor.diff:              logger.Debug(sprintf "sending message to %O" ip)
               sendMessage socket buffer
   
  -    // TODO any network connection  that throws an exception
  -    let makeConnectionLoop (box: MailboxProcessor<_>) =
  -        let rec connectionLoop (connections: Dictionary<IPAddress, ConnectionDetails>) =
  -            async { try
  -                        let! msg = box.Receive()
  -                        let deadSockets = 
  -                            connections 
  -                            |> Seq.filter (fun x -> not x.Value.Socket.Connected)
  -                            |> Seq.toList
  -                        for deadSocket in deadSockets do
  -                            connections.Remove(deadSocket.Key) |> ignore
  -                        match msg with
  -                        | Add socket ->
  -                            let cd = ConnectionDetails.Create socket 
  -                            let ip, _ = getRemoteAddress socket
  -                            connections.Add(ip, cd)
  -                            return! connectionLoop connections
  -                        | Remove socket -> 
  -                            // TODO this could fail, try removing by socket reference if it does
  -                            let ip, _ = getRemoteAddress socket
  -                            connections.Remove ip  |> ignore
  -                            return! connectionLoop connections
  -                        | Broadcast buffer ->
  -                            let sockets =
  -                                connections.Values |> Seq.map (fun x -> x.Socket) |> Seq.toArray
  -                            broadcast sockets buffer
  -                            return! connectionLoop connections
  -                        | SendMessage (address, buffer) ->
  -                            let succes, socket = 
  -                                connections.TryGetValue(address) 
  -                            match succes with
  -                            | true -> sendMessage socket.Socket buffer
  -                            | false -> logger.Error(sprintf "failed to send message to %O" address)
  -                            return! connectionLoop connections
  -                    with ex ->
  -                        logger.Warn(sprintf "SAVED event loop from %O" ex)
  -                        // TODO check if it's network excpetion and remove socket
  -                        return! connectionLoop connections }
  -        connectionLoop
  -
  -    let activeSendConnections =
  -        MailboxProcessor.Start(fun box ->
  -                                    let connectionLoop = makeConnectionLoop box
  -                                    connectionLoop (new Dictionary<IPAddress, ConnectionDetails>()))
  -
  -    let sendMessageTo address messageBuffer =
  -        activeSendConnections.Post(SendMessage(address, messageBuffer))
  -
  -    let startReadLoop socket =
  +    let startReadLoop (activeConnections: MailboxProcessor<_>) socket =
   
           let rec processSegements header (segments: ResizeArray<byte[]>) =
   
  
positive.code:                         return! loop header segments
                      with ex ->
                          logger.Error(printf "reading failed for %O exception was %O" socket.RemoteEndPoint ex)
                          activeSendConnections.Post(Remove socket) }
          loop None (new ResizeArray<byte[]>())
  
      let createAndStoreConnection address =
          async { try
                      logger.Info(sprintf "trying to connect to %O" address)
                      let! conn = AsyncSockets.OpenSendSocket address connDetails.Port
                      if conn.Connected then
                          activeSendConnections.Post (Add conn)
                          let addressRemote, portRemote = getRemoteAddress conn
                          let addressLocal, portLocal = getLocalAddress conn
                          let version = 
                              Version.CreateMyVersion 
                                  addressRemote (portRemote |> uint16) addressLocal (portLocal |> uint16)
                          let buffer = messageProcessor.CreateBufferWithHeader version MessageNames.Version
                          sendMessageTo address buffer
                          startReadLoop conn |> Async.Start
                          logger.Info(sprintf "connected to %O!" address)
                      else
                          logger.Error(sprintf "didn't connect to %O" address)
                  with ex -> 
                      logger.Error(sprintf "connection to address %O failed %O" address ex) }
  
      let startAcceptLoop() =
          // why? because msdn says so ... http://msdn.microsoft.com/en-us/library/dz10xcwh(v=vs.110).aspx
  
negative.code:     | Remove of Socket
      | Broadcast of byte[]
      | SendMessage of IPAddress * byte[]
      | ConnectFailed of IPAddress
  
  type MessageReceivedEventArgs(address: IPAddress, message: Message) =
      inherit EventArgs()
  