Windows Sockets Problem
Hi all
I’m trying to send a file using the windows sockets API’s and this is how I’m doing it:
'code for VB6
'first loading the file to a string buffer.
Open "File Name " For Binary As #1
Dim FileData As String
FileData = Space$(LOF(1))
Get #1, , FileData
Close #1
'now sending the file
Dim SendBuffer() As Byte
FileData = FileData & "FileEnd"
SendBuffer() = StrConv(FileData, vbFromUnicode)
Call send(Socket, Buffer(0), Len(FileData), 0&)
DoEvents
'I check if the file has arrived using the following routine
Public FileBuffer As String
Dim TempBuffer As String
Dim BytesReceived As Long
Dim ByteBuffer(1 To 8192) As Byte
BytesReceived = recv("The Socket Handel", _
ByteBuffer(1), _
8192, 0&)
If BytesReceived > 0 Then
TempBuffer = StrConv(ByteBuffer, vbUnicode)
If Right(TempBuffer, 7) = "FileEnd" Then
FileBuffer = FileBuffer & Left(TempBuffer, Len(TempBuffer) - 7)
Open "FileName" For Binary As #1
Put #1, , FileBuffer
Close #1
Else
FileBuffer = FileBuffer & TempBuffer
End If
End If
The problem starts if I try to send anything through
the same socket right after sending the file "For Example the file size"
because the condition : if right(TempBuffer,7)="FileEnd"
will always be false because the (TempBuffer =”The File data” and what ever information I send right after sending the file).
I tried to solve this problem using the “sleep( )” function after sending the file data, but it is not reliable. Is there a better way to do this without using another socket or using a long period for the sleep( ) function?
Any help is greatly appreciated.
Thanks all.
[edited by - Fma on July 2, 2002 6:44:38 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement