简体   繁体   English

检索移动连接上的Tcp / IP使用情况c#

[英]Retrieving Tcp/IP usage on a mobile connection c#

I am currently writing a system logging program which sends different logs via ftp. 我目前正在编写一个系统日志记录程序,它通过ftp发送不同的日志。 The Problem I am facing is that my program should constantly check if the connection is being used before and during it's upload in order to stop sending packets if a different program wants to use the connection. 我面临的问题是我的程序应该不断检查在上传之前和期间是否正在使用连接,以便在另一个程序想要使用连接时停止发送数据包。

I actually found this link helping me measure the speed of the connection, but I think I can only use the latter in order to discover if the something is already being streamed. 我实际上发现这个链接帮助我测量连接的速度,但我想我只能使用后者才能发现某些内容是否已经被流式传输。 After reading the library entry on System.Net.NetworkInformation, checking various Network Statistics and states wasn't a problem either. 在System.Net.NetworkInformation上读取库条目后,检查各种网络统计信息和状态也不是问题。 As stated beforehand my only problem is checking if some other program wants to send something. 如前所述,我唯一的问题是检查是否有其他程序要发送内容。

As you can probably tell from the question, I am very new to this topic and a fairly junior programmer. 正如你可以从问题中看出的那样,我对这个话题非常陌生并且是一个相当初级的程序员。 I have been reading up on the System.Net.NetworkInformation Namespace library and facilitating it's various classes, methods and delegates. 我一直在阅读System.Net.NetworkInformation命名空间库,并为其提供各种类,方法和委托。 I have the feeling that I am on the right track, but just not getting there. 我觉得我在正确的轨道上,但是没有到达那里。 Anyone got a push in the right direction? 任何人都朝着正确的方向努力?

Thank you. 谢谢。

I ended up using the System.Net.NetworkInformation library and it's methods. 我最终使用了System.Net.NetworkInformation库及其方法。

The methods GetIsNetworkAvailable(), NetworkChange.NetworkAvailabilityChanged Eventhandler and the TcpStatistics helped me gather information on the connection. 方法GetIsNetworkAvailable(),NetworkChange.NetworkAvailabilityChanged Eventhandler和TcpStatistics帮助我收集有关连接的信息。 MSDN and the reference is a great guide in using the foregone mentionend methods and I basically used the examples with slight modifications to suit my needs. MSDN和参考资料是使用已知的提及方法的一个很好的指南,我基本上使用这些例子稍作修改以满足我的需要。

msdn NetworkInformation: http://msdn.microsoft.com/de-de/library/system.net.networkinformation.aspx msdn NetworkInformation: http//msdn.microsoft.com/de-de/library/system.net.networkinformation.aspx

The GetIsNetworkAvailable is pretty straight forward returns boolean value on connection being up or down. 连接上升或下降时,GetIsNetworkAvailable非常直接返回布尔值。

Networkchange.NetworkAvailabilityChanged triggers an event on connection loss or reconnection. Networkchange.NetworkAvailabilityChanged在连接丢失或重新连接时触发事件。 See the msdn link above for an excellent and very usuable example on it's usage. 请参阅上面的msdn链接,了解它的用法的一个非常好用的例子。

And the TcpStatistics return information on how many connections have been accepted, initiated, errors received, failed connections, connection resets and more. 并且TcpStatistics返回有关已接受,启动,接收错误,连接失败,连接重置等连接数的信息。 These were the five I used so far to evaluate the connection. 这是我到目前为止评估连接的五个。

I realized that you do not really need any more to monitor the connection efficiently. 我意识到你真的不需要更多来有效地监控连接。 Maybe the method NetworkInterface.GetAllNetworkInterfaces() can help finding out which Networkadapter is sending the data and should be monitored. 也许NetworkInterface.GetAllNetworkInterfaces()方法可以帮助找出哪个Networkadapter正在发送数据并应该被监控。

I now understand the comments of Peter Ritchie to my question. 我现在理解Peter Ritchie对我的问题的评论。 FTP transmission runs extremely well and the protocol handles the transmission of the files flawlessly and no problems have arisen up until now in streaming the log files. FTP传输运行得非常好,协议可以完美地处理文件的传输,直到现在流式传输日志文件时才出现问题。 In 4 weeks of testing I have received the logging data constantly. 在4周的测试中,我不断收到测井数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM