当前位置: 首页>>代码示例>>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;未经允许,请勿转载。