Socket Receive Error

J

Joshua Frank

Hi,

I'm getting the strangest problem trying to receive from a socket. I'm
downloading a huge file. When I loop, receiving until I get no bytes back,
it works fine. But I wanted to update a progress bar during this process,
so I added a notification delegate and I call this each time through:

Dim Ret As Integer, Buffer(1023) As Byte
Do
Ret = theSocket.Receive(Buffer)
If Ret > 0 Then
If m_DownloadToFile Then
m_FileStream.Write(Buffer, 0, Ret)
Else
m_Data = m_Data + ASCII.GetString(Buffer, 0, Ret)
End If
m_TransferredBytes = m_TransferredBytes + Ret

'if we have a notification
If Not Notify Is Nothing Then
'notify
Call Notify(Ret) <------this causes the problem
End If
End If
Loop Until Ret = 0

But when I do this, I start losing bytes. If I don't call the Notify
delegate, the file is something like 36MB. But if I call it, I seem to lose
data, and the file only winds up at about 21MB. This is kind of hard to
debug, so before rolling up my sleeves, I was wondering if anyone with
socket experience could spot the problem right off. Any help much
appreciated. Thanks.

Cheers,

--
Joshua Frank
Senior Systems Architect
Archimetrics, L.L.C.
"Add some SpArk to your stored procedure development."
(web) http://www.archimetrics.com
(email) mailto:[email protected]
(voice) (973) 727-1510
 
I

Ivar

Hi,

Basicall you need implement some commands to get file, because thats it's
allowed
socket.Recive to return 0.

For example

Client Sends: SEND 122424<CRLF> - number is number of bytes will be
sended
Server replies: OK or ERROR <CRLF>
Client Sends: send file here - client must send exact bytes here,
Servre replies: read file and return OK<CRLF>

....

Simplier is use ftp, there isn't any need to invent bicycle if it already
exists !!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top