本文整理汇总了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;
}
}
示例2: HandleConnectionReceived
private void HandleConnectionReceived(StreamSocketListener listener,
StreamSocketListenerConnectionReceivedEventArgs args)
{
provider.StopAdvertising();
listener.Dispose();
DoConnect(args.Socket);
}
示例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));
}
}
示例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, "");
}
}
示例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;
}
}