Tag: networking

IPAddress。 Parse解析192.168到192.0.0.168

我有以下情况: IPAddress ip; IPAddress.TryParse(“192.168”, out ip); if(ip == null){//do something with IP} 我希望解析失败,而不是解析为“192.0.0.168”。 我在这里想念的是什么? (IPAddress.Parse的工作原理相同)

UdpClient – 限制缓冲区?

我在C#中遇到了UdpClient问题。 我通过互联网在两个客户端之间传输音频。 在我的麦克风上,采样率为16khz,我发送带有音频的UDP数据包,每个数据包6400字节。 这些从未通过,除了最后的数据包,自从我关闭录音以来通常大约在1200-3400之间。 当我将采样率降低到8khz时,我发送3200字节有效载荷的数据包。 这些总是因某种原因而通过。 因此,基本上3200以上的任何东西都会被拙劣(没有测试确切的数字,但……)为什么这个呢? 我想也许UdpClient内部缓冲区太小或什么的? 由于我流音频数据包被频繁发送。 接收: private void audioReceive(IAsyncResult asyn) { try { byte[] temp = audioSock.EndReceive(asyn, ref this.serverEP); this.waveProvider.AddSamples(temp, 0, temp.Length); this.textbox_display.Text = this.textbox_display.Text + ” got bytes: ” + temp.Length; audioSock.BeginReceive(new AsyncCallback(audioReceive), null); } catch (Exception ez) { MessageBox.Show(“audioReceive: ” + this.textbox_nick.Text + ” ” +ez.ToString()); } } 我找不到任何明显的错误。 […]

为什么HttpClient似乎在这里死锁?

我有一个在便携式类库中制作的API,需要使用特定于平台的API来发送HTTP请求。 这是我写的在WinRT上执行HTTP POST的方法: public bool Post(IEnumerable<KeyValuePair> headers, string data) { bool success = false; HttpClient client = new HttpClient(new HttpClientHandler {AllowAutoRedirect = false}); foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } try { var task=client.PostAsync(endpoint, new StringContent(data, Encoding.UTF8, “text/xml”)).ContinueWith( postTask => { try { postTask.Wait(client.Timeout); //Don’t wait longer than the client timeout. success = […]

如何获取域控制器IP地址

如何使用C#编程方式获取域控制器IP地址?

如何从任何IP和任何端口接收UDP数据包?

我想用C#的UdpClient来监听任何收到的UDP数据包。 我想从任何IP和任何端口接收数据包。 我尝试了以下方法: UdpClient udpClient = new UdpClient(0); IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); byte[] data = udpClient.Receive(ref ep); 但没有成功。 有谁知道什么是错的? 提前致谢!

我刚收到这个UDP数据包的适配器是什么?

我正在尝试用c#编写BOOTP服务器。 我正在从客户端接收并解析BOOTP数据包,我需要回复我的服务器IP地址。 问题是: 计算机可以有多个网络适配器 客户端还没有IP地址 有没有办法找出接收UDP数据包的适配器?

sockets-for-pcl没有按预期进行多播

我想在WP8.1上试验UDP多播,并在nuget上找到这个库 。 我创建了2个应用程序,一个在WP8.1上,一个在桌面上,我只提供C#代码,因为WPF在这里无关紧要。 WP8.1: public sealed partial class MainPage : Page { int port = 11811; string ip = “239.123.123.123”; UdpSocketMulticastClient udp; public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; } async protected override void OnNavigatedTo(NavigationEventArgs e) { udp = new UdpSocketMulticastClient(); udp.MessageReceived += (sender, args) => { var data = Encoding.UTF8.GetString(args.ByteData, 0, args.ByteData.Length); Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () […]

WinRT中的ICMP Ping – 有可能吗?

如何在WinRT Modern UI应用程序中执行ICMP ping? 目前在WinRT中没有实现Ping(请参阅此处的相关问题),以及Silverlight中以前的策略是: 使用WCF服务 调用Javascript然后调用ActiveX组件 放弃( 这里 ) Vasily 在这里使用http来“ping”特定端口上的Web服务器,使用StreamSocket支持使用TCP套接字进行网络通信。 也许Windows.Networking.Socket是我必须使用的最高级API,如果我想为WinRT编写自己的ICMP库。 此实现使用System.Net.Sockets来生成ICMP echo请求 – 在标准.NET中 此 WinRT示例使用Windows.Networking.Sockets.DatagramSocket类创建UDP套接字。 我认为我需要的是原始套接字来做ICMP。 这甚至可以在WinRT沙箱中进行ICMP ping吗?

NetworkInterface.GetIPv4Statistics()。BytesReceived – 它返回什么?

特定领域的回报是什么? 我想要每秒接收的字节数。 我应该依靠这个吗?

无法从WinRT连接到远程服务器

我正在制作一个应用程序,基本上只需要将一段XML发送到服务器并返回。 我遇到了麻烦,但要让它工作并得到非常奇怪的错误 public bool Post(string data) { string server=”http://my-lan-computer:9091/foo” bool success = false; HttpClient client = new HttpClient(); try { client.PostAsync(server, new StringContent(data, Encoding.UTF8, “text/xml”)).Wait(); //error here success = true; } catch { } return success; } 我发布的服务器不是localhost,但它是我本地网络上的一台计算机。 我深深嵌套这个错误: innerException: {“An error occurred while sending the request.”} innerException: {“Unable to connect to the remote server”} […]