@@ -45,7 +45,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
4545 }
4646 private void CleanupResources ( )
4747 {
48- Debug . WriteLine ( "清理资源 " ) ;
48+ Debug . WriteLine ( "清理接收资源 " ) ;
4949 // 1. 停止WiFi广播
5050 if ( _publisher . Status == WiFiDirectAdvertisementPublisherStatus . Started )
5151 {
@@ -164,11 +164,11 @@ private void BeginBroadcast()
164164 _publisher . Advertisement . IsAutonomousGroupOwnerEnabled = true ;
165165 _publisher . Advertisement . ListenStateDiscoverability =
166166 WiFiDirectAdvertisementListenStateDiscoverability . Normal ;
167- Debug . WriteLine ( "开始扫描 " ) ;
167+ Debug . WriteLine ( "开始广播 " ) ;
168168 _publisher . Start ( ) ;
169169 if ( _publisher . Status != WiFiDirectAdvertisementPublisherStatus . Started )
170170 {
171- Debug . WriteLine ( "扫描失败 " ) ;
171+ Debug . WriteLine ( "广播失败 " ) ;
172172 }
173173
174174 //AssociationEndpoint 关联的终结点。 这包括其他电脑、平板电脑和手机。
@@ -181,6 +181,7 @@ private void BeginBroadcast()
181181 new string [ ] { "System.Devices.WiFiDirect.InformationElements" }
182182 ) ;
183183 connectionListener . ConnectionRequested += ConnectionRequestedHandler ;
184+ Debug . WriteLine ( "开始监听" ) ;
184185 }
185186 else
186187 {
@@ -198,23 +199,25 @@ private async void ConnectionRequestedHandler(
198199 var request = args . GetConnectionRequest ( ) ;
199200 try
200201 {
201- var device = await WiFiDirectDevice . FromIdAsync ( request . DeviceInformation . Id ) ;
202- if ( device . ConnectionStatus == WiFiDirectConnectionStatus . Connected )
202+ //var device = await WiFiDirectDevice.FromIdAsync(request.DeviceInformation.Id);
203+ //if (device == null)
204+ // return;
205+ //if (device.ConnectionStatus == WiFiDirectConnectionStatus.Connected)
206+ //{
207+ // var endpointPairs = device.GetConnectionEndpointPairs();
208+ // foreach (var pair in endpointPairs)
209+ // {
210+ // 启动文件接收器
211+ if ( receiver . IsListening == false )
203212 {
204- var endpointPairs = device . GetConnectionEndpointPairs ( ) ;
205- foreach ( var pair in endpointPairs )
206- {
207- // 启动文件接收器
208- if ( receiver . IsListening == false )
209- {
210- Debug . WriteLine ( $ "LocalServiceName:{ pair . LocalServiceName } RemoteServiceName:{ pair . RemoteServiceName } ") ;
211- Debug . WriteLine ( $ "LocalHostName:{ pair . LocalHostName } RemoteHostName:{ pair . RemoteHostName } ") ;
213+ //Debug.WriteLine($"LocalServiceName:{pair.LocalServiceName} RemoteServiceName:{pair.RemoteServiceName}");
214+ //Debug.WriteLine($"LocalHostName:{pair.LocalHostName} RemoteHostName:{pair.RemoteHostName}");
212215
213- await receiver . StartAsync ( port ) ;
216+ await receiver . StartAsync ( port ) ;
214217
215- }
216- }
217218 }
219+ // }
220+ //}
218221 }
219222 catch ( Exception ex )
220223 {
0 commit comments