async void streamSocketListner_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args) { ResponsConfigDictionary[ResponsConfigDictionaryIdCounter] = new ResponseConfig(ResponsConfigDictionaryIdCounter, args.Socket); bool allowconnection = false; switch (this.allow) { case ("lan"): Tuple<HostName, HostName> mylocal = GetStartEndIP(); List<HostName> mylocalfriends = (mylocal != null) ? GetIpList(mylocal) : null; if(mylocalfriends != null) { var lanfriend = mylocalfriends.SingleOrDefault<HostName>(o => o.DisplayName.Equals(args.Socket.Information.RemoteAddress.DisplayName)); if (lanfriend != null) allowconnection = true; } if (args.Socket.Information.RemoteAddress.IPInformation != null) { if (args.Socket.Information.LocalAddress.IPInformation.NetworkAdapter.NetworkAdapterId == args.Socket.Information.RemoteAddress.IPInformation.NetworkAdapter.NetworkAdapterId) { allowconnection = true; } } break; case ("any"): allowconnection = true; break; default: if (args.Socket.Information.RemoteAddress.IPInformation != null) { if (args.Socket.Information.LocalAddress.IPInformation.NetworkAdapter.NetworkAdapterId == args.Socket.Information.RemoteAddress.IPInformation.NetworkAdapter.NetworkAdapterId) { allowconnection = true; } } break; } if (allowconnection) { int responseId = ResponsConfigDictionaryIdCounter; ResponsConfigDictionaryIdCounter++; bool suc = false; try { suc = await SendResponse(MPDKeyWords.Response.RESPONSE_SUCCESS_CONNECT, args.Socket); } catch { suc = false; } if (suc) { await ReadResponse(args.Socket, responseId); } } }