public async Task <AsyncHandleResult> AddStreamSocketAsync( ServiceSession session, UInt16 port ) { WFDSvcWrapperHandle socketHandle = null; Exception error = null; bool success = false; try { ThrowIfDisposed(); WiFiDirectTestLogger.Log( "AddStreamSocketAsync... (port={0}) (Session={1})", port.ToString(), session.Handle ); StreamSocketListenerWrapper listener = await session.AddStreamSocketListenerAsync(port); listener.WaitForConnection(); socketHandle = listener.LastSocketHandle; success = true; } catch (Exception ex) { WiFiDirectTestLogger.Log("Exception in AddStreamSocketAsync (this may be expected)"); error = ex; } return(new AsyncHandleResult(socketHandle, success, error)); }
public async void AddStreamSocketListenerAsync(UInt16 port) { ThrowIfDisposed(); manager.NotifyUser("Adding stream socket listener for TCP port " + port, NotifyType.StatusMessage); var endpointPairCollection = session.GetConnectionEndpointPairs(); // Create listener for socket connection (and add to list to cleanup later) StreamSocketListener listenerSocket = new StreamSocketListener(); StreamSocketListenerWrapper listenerWrapper = new StreamSocketListenerWrapper( manager, listenerSocket, this ); streamSocketListeners.Add(listenerWrapper); manager.NotifyUser("BindEndpointAsync...", NotifyType.StatusMessage); await listenerSocket.BindEndpointAsync(endpointPairCollection[0].LocalHostName, Convert.ToString(port, CultureInfo.InvariantCulture)); manager.NotifyUser("BindEndpointAsync Done", NotifyType.StatusMessage); manager.NotifyUser("AddStreamSocketListenerAsync...", NotifyType.StatusMessage); await session.AddStreamSocketListenerAsync(listenerSocket); manager.NotifyUser("AddStreamSocketListenerAsync Done", NotifyType.StatusMessage); }