/// <summary> /// Stop voice recording. /// </summary> private async void StopCapture(MediaElement mediaElement) { if (Status != RecorderStatus.Recording) { return; } Debug.WriteLine("Stopping recording"); await _mediaCapture.StopRecordAsync(); Debug.WriteLine("Stop recording successful"); Status = RecorderStatus.Initial; _recordingStream.Seek(0); //mediaElement.AutoPlay = true; //mediaElement.SetSource(_recordingStream, ""); //mediaElement.Play(); //var buffer = new Windows.Storage.Streams.Buffer(4000000); //await _recordingStream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None); //var bytes = buffer.ToArray(); var clientDatagramSocket = new Windows.Networking.Sockets.DatagramSocket(); var hostName = new Windows.Networking.HostName(HostName); await clientDatagramSocket.ConnectAsync(hostName, Port); using (var serverDatagramSocket = new Windows.Networking.Sockets.DatagramSocket()) { using (Stream outputStream = (await serverDatagramSocket.GetOutputStreamAsync(hostName, Port)).AsStreamForWrite()) { var buffer = new Windows.Storage.Streams.Buffer(MaxUdpPackageSize); while (true) { var retrievedBuffer = _recordingStream.ReadAsync(buffer, MaxUdpPackageSize, InputStreamOptions.None).GetResults(); if (retrievedBuffer == null || retrievedBuffer.Length < 1) { break; } outputStream.Write(retrievedBuffer.ToArray(), 0, (int)retrievedBuffer.Length); outputStream.Flush(); } } } }
/// <summary> /// Retrieve the current network time from ntp server "time.windows.com". /// </summary> public async void GetNetworkTime(string ntpServer) { averageNtpRTT = 0; //reset currentNtpQueryCount = 0; //reset minNtpRTT = -1; //reset //NTP uses UDP ntpSocket = new Windows.Networking.Sockets.DatagramSocket(); ntpSocket.MessageReceived += OnNTPTimeReceived; if (ntpQueryTimer == null) { ntpQueryTimer = new Windows.UI.Xaml.DispatcherTimer(); ntpQueryTimer.Tick += NTPQueryTimeout; ntpQueryTimer.Interval = new TimeSpan(0, 0, 5); //5 seconds } if (ntpRTTIntervalTimer == null) { ntpRTTIntervalTimer = new Windows.UI.Xaml.DispatcherTimer(); ntpRTTIntervalTimer.Tick += SendNTPQuery; ntpRTTIntervalTimer.Interval = new TimeSpan(0, 0, 0, 0, 200); //200ms } ntpQueryTimer.Start(); try { //The UDP port number assigned to NTP is 123 await ntpSocket.ConnectAsync(new Windows.Networking.HostName(ntpServer), "123"); ntpRTTIntervalTimer.Start(); } catch (Exception e) { Debug.WriteLine($"NtpSync: Exception when connect socket: {e.Message}"); ntpResponseMonitor.Stop(); ReportNtpSyncStatus(false); } }
private async void UdpClient() { try { socket = new Windows.Networking.Sockets.DatagramSocket(); socket.MessageReceived += Socket_MessageReceived; serverHost = new Windows.Networking.HostName(serverIP); await socket.ConnectAsync(serverHost, port); udpReady = true; ConnectButton.Content = "Connected!"; } catch (Exception e) { } }
public UpStreamMgr() { var tunnelSocket = new Windows.Networking.Sockets.DatagramSocket(); tunnelSocket.ConnectAsync(new HostName("127.0.0.1"), "23123").AsTask().Wait(); }
/// <summary> /// Retrieve the current network time from ntp server "time.windows.com". /// </summary> public async void GetNetworkTime(string ntpServer) { averageNtpRTT = 0; //reset currentNtpQueryCount = 0; //reset minNtpRTT = -1; //reset //NTP uses UDP ntpSocket = new Windows.Networking.Sockets.DatagramSocket(); ntpSocket.MessageReceived += OnNTPTimeReceived; if (ntpQueryTimer == null) { ntpQueryTimer = new Windows.UI.Xaml.DispatcherTimer(); ntpQueryTimer.Tick += NTPQueryTimeout; ntpQueryTimer.Interval = new TimeSpan(0, 0, 5); //5 seconds } if (ntpRTTIntervalTimer == null) { ntpRTTIntervalTimer = new Windows.UI.Xaml.DispatcherTimer(); ntpRTTIntervalTimer.Tick += SendNTPQuery; ntpRTTIntervalTimer.Interval = new TimeSpan(0, 0, 0, 0, 200); //200ms } ntpQueryTimer.Start(); try { //The UDP port number assigned to NTP is 123 await ntpSocket.ConnectAsync(new Windows.Networking.HostName(ntpServer), "123"); ntpRTTIntervalTimer.Start(); } catch (Exception e) { Debug.WriteLine($"NtpSync: Exception when connect socket: {e.Message}"); ntpResponseMonitor.Stop(); ReportNtpSyncStatus(false); } }