當前位置: 首頁>>代碼示例>>C#>>正文


C# StreamSocketListener.Dispose方法代碼示例

本文整理匯總了C#中Windows.Networking.Sockets.StreamSocketListener.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# StreamSocketListener.Dispose方法的具體用法?C# StreamSocketListener.Dispose怎麽用?C# StreamSocketListener.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Networking.Sockets.StreamSocketListener的用法示例。


在下文中一共展示了StreamSocketListener.Dispose方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StartServer

 public async Task<bool> StartServer()
 {
     Listener = new StreamSocketListener();
     // Removes binding first in case it was already bound previously.
     Listener.ConnectionReceived -= Listener_ConnectionReceived;
     Listener.ConnectionReceived += Listener_ConnectionReceived;
     try
     {
         await Listener.BindServiceNameAsync("4555"); // Your port goes here.
         if(globalDataSet.DebugMode) Debug.Write("Server started \n");
         return true;
     }
     catch (Exception ex)
     {
         Listener.ConnectionReceived -= Listener_ConnectionReceived;
         Listener.Dispose();
         return false;
     }
 }
開發者ID:MRixen,項目名稱:MovementDiagnose_Server,代碼行數:19,代碼來源:ServerComm.cs

示例2: HandleConnectionReceived

 private void HandleConnectionReceived(StreamSocketListener listener,
   StreamSocketListenerConnectionReceivedEventArgs args)
 {
   provider.StopAdvertising();
   listener.Dispose();
   DoConnect(args.Socket);
 }
開發者ID:Remmo,項目名稱:WpWinNl,代碼行數:7,代碼來源:DevicePairConnectionHelper.cs

示例3: ListenerOnConnectionReceived

        private void ListenerOnConnectionReceived(StreamSocketListener Listener, StreamSocketListenerConnectionReceivedEventArgs Args)
        {
            var deviceName = "";
            var serviceName = "";
            HostName hostName = null;
            
            try
            {
                // Only supports a single connection for the moment so we won't need these again
                _serviceProvider.StopAdvertising();
                Listener.Dispose();

                _socket = Args.Socket;
                _writer = new DataWriter(_socket.OutputStream);
                _reader = new DataReader(_socket.InputStream);

                if (_socket.Information != null)
                {
                    // Turns out this only gives us the host address and an
                    // arbitrary number for service name. Pretty useless.
                    deviceName = _socket.Information.RemoteHostName.DisplayName;
                    hostName = _socket.Information.RemoteHostName;
                    serviceName = _socket.Information.RemoteServiceName;
                }
            } 
            catch (Exception ex)
            {
                ServerState = BluetoothServerState.Faulted;
                if (ConnectionError != null)
                    ConnectionError(this, ex);

                return;
            }

            ServerState = BluetoothServerState.Connected;
            if (ClientConnected != null)
            {
                var device = new BluetoothDevice(deviceName, hostName, serviceName);
                var connection = new DuplexConnection(_reader, _writer);
                ClientConnected(this, new ClientConnectedEventArgs(device, connection));
            }
        }
開發者ID:peterdn,項目名稱:Geomoir,代碼行數:42,代碼來源:BluetoothServer.cs

示例4: _bluetooth_connection_received

        private async void _bluetooth_connection_received(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            try
            {
                scan_transfer_speed();
                
                _datareader = new DataReader(args.Socket.InputStream);
                _datareader.InputStreamOptions = InputStreamOptions.Partial;

                _datawriter_foracks = new DataWriter(args.Socket.OutputStream);

                StorageFolder folder = KnownFolders.PicturesLibrary;
                StorageFile file = await folder.CreateFileAsync(this.filepath, CreationCollisionOption.ReplaceExisting);

                IRandomAccessStream filestream = await file.OpenAsync(FileAccessMode.ReadWrite);
                IOutputStream filewriter = filestream.GetOutputStreamAt(0);

                _datawriter = new DataWriter(filewriter);

                while (!((_length = await _datareader.LoadAsync(65000)) == 0))
                {
                    while (_writing) { }

                    _transferspeed += _length;

                    _buffer = new byte[_length];
                    _datareader.ReadBytes(_buffer);

                    _datawriter.WriteBytes(_buffer);
                    await _datawriter.StoreAsync();
                }

                _datawriter.Dispose();
                filewriter.Dispose();
                filestream.Dispose();
                _datareader.Dispose();

                _transferspeed /= 1024;
                _message = format_message(_stopwatch.Elapsed, "Transferspeed", _transferspeed.ToString(), "kB/s");
                this.callback.on_transfer_speed_change(_message, this.results);
                this.main_view.text_to_logs(_message.Replace("\t", " "));

                _timer.Cancel();
                
                sender.Dispose();
                _bluetooth_listener.Dispose();

                _message = format_message(_stopwatch.Elapsed, "File Transfer", "OK", this.filepath);
                this.callback.on_file_received(_message, this.results);
                this.main_view.text_to_logs(_message.Replace("\t", " "));

                _stopwatch.Stop();
            }
            catch (Exception e)
            {
                append_error_tolog(e, _stopwatch.Elapsed, "");
            }
        }
開發者ID:StabilityofWT,項目名稱:Stability-Monitor,代碼行數:58,代碼來源:Bluetooth_agent.cs

示例5: StartServer

        // This is the static method used to start listening for connections.

        public static async Task<bool> StartServer()
        {
            InitGPIO();
            timer = new Timer(TimerCallback, null, 0, timerTime);

            Listener = new StreamSocketListener();
            // Removes binding first in case it was already bound previously.
            Listener.ConnectionReceived -= Listener_ConnectionReceived;
            Listener.ConnectionReceived += Listener_ConnectionReceived;
            try
            {
                await Listener.BindServiceNameAsync("4555"); // Your port goes here.
                Debug.Write("Server started \n");
                return true;
            }
            catch (Exception ex)
            {
                Listener.ConnectionReceived -= Listener_ConnectionReceived;
                Listener.Dispose();
                return false;
            }
        }
開發者ID:MRixen,項目名稱:GetCake_ServerApp,代碼行數:24,代碼來源:ServerClass.cs


注:本文中的Windows.Networking.Sockets.StreamSocketListener.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。