Solved

Unexplained connection drop in the middle of an FTP transmission using GPRS

Posted on 2008-06-23
11
783 Views
Last Modified: 2013-12-27
I have written two applications that communicate with each other via wireless GPRS. One of these applications runs on a Pocket PC under WM5 or WM6 and the other runs on a desktop. Both programs were developed using Visual Basic .Net under Visual Studio 2005.

The desktop application works as a server and continuously 'listens' for the Pocket PC application wanting to connect. The PPC application then requests connection with the desktop app. After the connection is accepted, the PPC app sends a file to the desktop app. To achieve this, an FTP connection is opened and the file is sent as a stream to the desktop app.

The problem:
 
The problem is that, for large files, the open connection is consistently dropped for some reason in the middle od the transmission. When it happens, it is always when the nws.Write statement in the enclosed code snippet is executed. For small data files there is no problem. The problem occurs after "nws.Write has been executed a few times.

It seems to me that the problem is connected with some kind of "maximum duration of transmission" setting. I conclude this since when the PPC is merely in a GPRS area, the connection always seems to be dropped about 15 seconds into the transmission. However, when I am in an area where HSDPA is available and send the same file the transmission gets much further.

There is no timeout explicitely programmed in the application.

I would appreciate any help in solving this (for me) tricky problem.

The following is the source code within the PPC app  which sends the 'file to the server program in the desktop computer: 
 

Try

     Dim BufferSize As Integer = FtpClient.ReceiveBufferSize
 

     nws = FtpClient.GetStream

     If Not nws.CanWrite Or Not nws.CanRead Then GoTo ExitSub

     '---open the file

     Dim fs As New FileStream(FtpFileName, FileMode.Open, FileAccess.Read)

     Dim bytesToSend(CInt(fs.Length) - 1) As Byte
 

     ' Voortgangsscherm tonen

      Dim FileName As String = Strings.Right(FtpFileName, FtpFileName.Length - Strings.InStrRev(FtpFileName, "\"))

     myVoortGang.Visible = True

     myVoortGang.text = TEKST(1033) & " " & FileName  ' 1033="Upload"

     myVoortGang.ProgressBarMax = CInt(fs.Length)

     myVoortGang.ProgressBarValue = 0

     Invoke(delUpdateVoortgang, myVoortGang)
 

     Dim numBytesRead As Integer = fs.Read(bytesToSend, 0, bytesToSend.Length)

     Dim totalBytes As Integer = 0

     For i As Integer = 0 To CInt(fs.Length \ BufferSize)

         '---send the file

         If fs.Length - (i * BufferSize) > BufferSize Then

             nws.Write(bytesToSend, i * BufferSize, BufferSize)

             totalBytes += BufferSize

         Else

             nws.Write(bytesToSend, i * BufferSize, CInt(fs.Length) - (i * BufferSize))

             totalBytes += CInt(fs.Length) - (i * BufferSize)

         End If

         myVoortGang.Visible = True

         myVoortGang.ProgressBarValue = totalBytes

         Invoke(delUpdateVoortgang, myVoortGang)

     Next

     fs.Close()

     nws.Close()

     FtpClient.Close()

     Catch ex As Exception

          GoTo ExitSub

End Try
 

This is received by the following source code in the desktop application::
 

Dim TimeStart As DateTime = Now

Do

     If nws.DataAvailable Then

          'nieuwe data : timeout verlengen

          TimeStart = Now

          '---read the incoming data

          Dim bytesRead As Integer = nws.Read(data, 0, FtpClient.ReceiveBufferSize)

          totalBytes += bytesRead

          fs.Write(data, 0, bytesRead)

     End If

Loop While CInt(Now.Subtract(TimeStart).TotalSeconds) < 2 And totalBytes <> lsFileSize

Open in new window

0
Comment
Question by:Pirie
  • 6
  • 5
11 Comments
 
LVL 11

Expert Comment

by:melmers
ID: 21872149
Have you tried to reduce the buffer size to execute the write method much faster and if your gprs connection drops when you are writing to the stream not all bytes are lost.

The second thougt is when i understand your code you write everytime the full buffer size
what happens when your data is not x * buffersize ?
0
 

Author Comment

by:Pirie
ID: 21873143
I haven't tried reducing the buffer size. Do you think that this would prevent the connection from being dropped in the first place since that is the problem I'm having?

The sending code does not in fact always send a whole buffer for the last/only buffer. This is handled in the Else clause of 'If fs.Length - (i * BufferSize) > BufferSize Then' in the Code Snippet.  

Do you have any ideas as to how to prevent the connection from being dropped at almost exactly the same point (about 15 seconds into the transmission) when I repeatedy send the same large file?
0
 
LVL 11

Expert Comment

by:melmers
ID: 21873218
I think it could be a gprs connection thing because i have seen sometimes when i load huge web pages with my gprs handy then the connection icon goes sometimes away and then the handy connects again without any user action. so i think you should try to reduce the packetsize and/or to implement a resume send function. Are there any exceptions on the ppc side that throws from your code ?
0
 

Author Comment

by:Pirie
ID: 21873376
The only error message I get on the PPC side is something like "Transport connection lost" when the program tries to send the next buffer after a disconnection.  I haven't tried to trap this.

When you talk about implementing a 'resume send' function, do you mean that this is a atandard GPRS function (maybe a setting?) or that I need to program a reconnect myself in VB followed by a  resend from the first frame that failed? Either way, if you have an example of how that should be done I would be grateful if I could receive it.
0
 
LVL 11

Expert Comment

by:melmers
ID: 21873414
When you become the message Transport connection lost then your physical link is dropped and
it has nothing with your code. When you trap this with an try catch block you can try to open the connection again and send the data again. You must look at your desktop application that if your
connection get lost on the ppc is it lost on the app too? if not then you can try to send the failed frame again.

Resume send is not a gprs function, you must implement it by yourself. sorry i have no snippet for
you.

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Pirie
ID: 21874748
What I'm really looking for is the reason why the connection is dropped in the first place and how to prevent this. The disconnection happens time after time for large files and always at the same place (after about 15 seconds with an ordinary GPRS speed) so it's systematic and not an occasional fluke. If HSDPA is available then the transmission consistently goes a lot farther and for most files is completed normally.
0
 
LVL 11

Accepted Solution

by:
melmers earned 500 total points
ID: 21881243
Could it be that your destop application resets the connection ?
in the part of the code of desktop application you have included an timeout of 2 seconds.

Loop While CInt(Now.Subtract(TimeStart).TotalSeconds) < 2 And totalBytes <> lsFileSize

when your ppc software needs over 2 second to send your data packet your desktop app exits the loop. you can try to give your ppc more time to send the data
0
 

Author Comment

by:Pirie
ID: 21882144
I increased toe 2 second timeout to a ridiculously high value (2000 seconds) and did a test. Unfortunately, the transmission aborted at the same place in the same way so that's not the answer.

Do you know of any good high level commercial libraries for GPRS file transmission that I could link into my VB.Net applications (also for the Compact Framework on the Pocket PC). Such a library would presumably have extensive facilities for error recovery and resumption of transmission. That could also be a solution as far as I am concerned.
0
 
LVL 11

Expert Comment

by:melmers
ID: 21882177
Sorry i have no idea where you can get an GPRS Library. you can search on www.componentsource.com for a library.
http://www.componentsource.com/products/rebex-ftp-net-cf/summary.html

Have you tried to download/upload a file with another ftp client with your ppc ? if the ftp client software aborts to it could be your ppc which makes the problem.
0
 

Author Closing Comment

by:Pirie
ID: 31469881
Your suggestion 'Could it be that your desktop application resets the computer?' put me on the right track. The problem was not the timeout of 2 seconds but your suggestion caused me to look for other places that could reset the connection. There I found the problem. A separate loop was polling all PPC's via a separate port to see if they were still available and, if not, resetting the connection. Obviously the connection was so busy that the PPC couldn't reply to the polling in time. I confirmed this by temporarilly removing the polling and then the file transmission went through to the end.

Thanks very much for your tip.

 
0
 

Author Comment

by:Pirie
ID: 21882300
Your suggestion 'Could it be that your desktop application resets the computer?' put me on the right track. The problem was not the timeout of 2 seconds but your suggestion caused me to look for other places that could reset the connection.

There I found the problem. A separate loop was polling all PPC's via a separate port to see if they were still available and, if not, resetting the connection. Obviously the connection was so busy that the PPC couldn't reply to the polling in time. I confirmed this by temporarilly removing the polling and then the file transmission went through to the end.

Now to implement  the solution, but that's not so difficult if you have identified the cause.
 
Thanks very much for your tip.

 
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This subject  of securing wireless devices conjures up visions of your PC or mobile phone connecting to the Internet through some hotspot at Starbucks. But it is so much more than that. Let’s look at the facts: devices#sthash.eoFY7dic.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now