void PeerNearMe_PeerNearMeChanged(object sender, PeerNearMeChangedEventArgs e) { var peerNearMe = e.PeerNearMe; if (peerNearMe == null) { return; } switch (e.PeerChangeType) { case PeerChangeType.Added: peerNearMe.RefreshDataCompleted += peerNearMe_RefreshDataCompleted; peerNearMe.RefreshDataAsync("Added"); AddLog("[Added]PeerNearMe_PeerNearMeChanged", LogType.System); break; case PeerChangeType.Deleted: peerNearMe.RefreshDataCompleted -= peerNearMe_RefreshDataCompleted; AddLog("[Deleted]PeerNearMe_PeerNearMeChanged", LogType.System); break; case PeerChangeType.Updated: peerNearMe.RefreshDataAsync("Updated"); AddLog("[Updated]PeerNearMe_PeerNearMeChanged", LogType.System); break; default: throw new NotImplementedException(); } }
// 自訂當Peer端點登入或登出時所呼叫的方法 private void PeerNearMeChangedCallback(Object sender, PeerNearMeChangedEventArgs e) { String str = ""; PeerNearMe pnm = e.PeerNearMe as PeerNearMe; // 取得Peer端點的位置 PeerEndPointCollection pepc = pnm.PeerEndPoints; foreach (PeerEndPoint pep in pepc) { // 回傳System.Net.IPEndPoint物件 IPEndPoint ipEndPoint = pep.EndPoint; // 取得Peer端點的IP位址 str = str + ", " + ipEndPoint.Address.ToString() + ":"; // 取得Peer端點的通訊埠 str = str + ipEndPoint.Port.ToString(); } // 取得PeerNearMe物件所發生的變更類型 switch (e.PeerChangeType) { // 當有新的Peer端點登入時 case PeerChangeType.Added: lstPeer.Items.Add(str); break; // 當Peer端點登出時 case PeerChangeType.Deleted: break; // 當Peer端點因相關資訊更新時 case PeerChangeType.Updated: lstPeer.Items.Add(str); break; default: break; } }
void PeerNearMe_PeerNearMeChanged(object sender, PeerNearMeChangedEventArgs e) { var peerNearMe = e.PeerNearMe; if (peerNearMe == null) return; switch (e.PeerChangeType) { case PeerChangeType.Added: peerNearMe.RefreshDataCompleted += peerNearMe_RefreshDataCompleted; peerNearMe.RefreshDataAsync("Added"); AddLog("[Added]PeerNearMe_PeerNearMeChanged", LogType.System); break; case PeerChangeType.Deleted: peerNearMe.RefreshDataCompleted -= peerNearMe_RefreshDataCompleted; AddLog("[Deleted]PeerNearMe_PeerNearMeChanged", LogType.System); break; case PeerChangeType.Updated: peerNearMe.RefreshDataAsync("Updated"); AddLog("[Updated]PeerNearMe_PeerNearMeChanged", LogType.System); break; default: throw new NotImplementedException(); } }