3

I am currently writing a system logging program which sends different logs via 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. 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. 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.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
Ben McDougall
  • 251
  • 2
  • 12
  • Is there a particular mobile platform that you had in mind? – Peter Ritchie Jul 19 '12 at 18:38
  • TCP/IP supports multiple simultanious connections (although, to different sockets); what are you doing to make you need to disconnect at connection so another program can use it? – Peter Ritchie Jul 19 '12 at 18:40
  • It is an embedded version of windows 7 or xp. Basically two other programs will mainly be using the tcp/ip connection. I know about the sockets just have to stop transmitting the stream of logging information if one of the other programs requires the connection. Is that understandable? – Ben McDougall Jul 19 '12 at 19:49
  • I'm still not clear why you have to disconnect on program in order for another to use tcp/ip. The logging server should be able to handle multiple connections--especially if it's ftp. – Peter Ritchie Jul 19 '12 at 20:22
  • The problem is the limited Bandwidth as the data is sent via a GPRS connection and is a Computer located on ambulances. Not worried about the server just the programs I will be logging have failed to send or receive information periodically during the last weeks and nobody knows why. If you suggest that I should not worry about the bandwidth or finishing my uploading of log files, which are compressed and only about 2-5KB of size that is fine. I just have to find out at which point the 3rd party Software is failing. Sorry if I was not able to express my difficulties correctly. – Ben McDougall Jul 19 '12 at 21:23

1 Answers1

1

I ended up using the System.Net.NetworkInformation library and it's methods.

The methods GetIsNetworkAvailable(), NetworkChange.NetworkAvailabilityChanged Eventhandler and the TcpStatistics helped me gather information on the connection. 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 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.

Networkchange.NetworkAvailabilityChanged triggers an event on connection loss or reconnection. See the msdn link above for an excellent and very usuable example on it's usage.

And the TcpStatistics return information on how many connections have been accepted, initiated, errors received, failed connections, connection resets and more. 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.

I now understand the comments of Peter Ritchie to my question. 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. In 4 weeks of testing I have received the logging data constantly.

Ben McDougall
  • 251
  • 2
  • 12