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 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:
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
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
nws.Write(bytesToSend, i * BufferSize, CInt(fs.Length) - (i * BufferSize))
totalBytes += CInt(fs.Length) - (i * BufferSize)
myVoortGang.Visible = True
myVoortGang.ProgressBarValue = totalBytes
Catch ex As Exception
This is received by the following source code in the desktop application::
Dim TimeStart As DateTime = Now
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)
Loop While CInt(Now.Subtract(TimeStart).TotalSeconds) < 2 And totalBytes <> lsFileSize