I am developing one project for my Company which includes one Server side
application and n nos of clients at various locations. I am facing problem
in transfering file from A client to B client via Server.
I am using winsock control.
I am opening file on A SIDE CLIENT in Binary format to send to server using
following commands :
Dim BufFile As String
Dim LnFile As Long
Dim nLoop As Long
Dim nRemain As Long
Dim Cn As Long
SrcPath = frmFileTransfer.txtLocalPath.Text
LnFile = FileLen(SrcPath)
If LnFile > 8192 Then
nLoop = Fix(LnFile / 8192)
nRemain = LnFile Mod 8192
Else
nLoop = 0
nRemain = LnFile
End If
If LnFile = 0 Then
MsgBox "Invalid file format", vbCritical, "File Send Error!"
Exit Function
End If
Open SrcPath For Binary As #1
If nLoop > 0 Then
For Cn = 1 To nLoop
BufFile = String(8192, " ")
Get #1, , BufFile
sckChat(0).SendData BufFile
frmFileTransfer.lbByteSend.Caption = "Bytes Sent: " & Cn * 8192
& " of " & LnFile
frmFileTransfer.lbByteSend.Refresh
ServerResponse = False
While ServerResponse = False
DoEvents
frmWait.lblStatus.Caption = "Waiting for server response..."
frmWait.lblLoop.Caption = Cn & " Out of " & nLoop
Wend
frmWait.lblStatus.Caption = "Server response received"
Next
If nRemain > 0 Then
BufFile = String(nRemain, " ")
Get #1, , BufFile
sckChat(0).SendData BufFile
frmFileTransfer.lbByteSend.Caption = "Bytes Sent: " & LnFile & "
of " & LnFile
frmFileTransfer.lbByteSend.Refresh
ServerResponse = False
While ServerResponse = False
DoEvents
Wend
End If
Else
BufFile = String(nRemain, " ")
Get #1, , BufFile
sckChat(0).SendData BufFile
frmFileTransfer.lbByteSend.Caption = "Bytes Sent: " & LnFile & "
of " & LnFile
frmFileTransfer.lbByteSend.Refresh
ServerResponse = False
While ServerResponse = False
DoEvents
Wend
End If
sckChat(0).SendData "EOF<br>" & Cn
Close #1
**************
SERVER should receive and forward same packets to B CLIENT using following
code
Dim mToIndex
Dim mCnt
mCnt = 0
mToIndex = Rs("FileToTrfIndex")
sckChat(mToIndex).SendData mStrData
mCnt = mCnt + 1
sckChat(FromIndex).SendData "REC"
***************
B client should write a file using following code
BytesRec = BytesRec + Len(fulldata)
Put #FL, , RecBuffer
frmFileProgress.lbBytesReceived.Caption = "Bytes received: " &
BytesRec
sckChat(0).SendData "CON"
**********
Above code works fine, and sent packets are received properly on server
side. I am forwarding these packets to CLIENT B, which surprisingly getting
bytes in double the sizes.
If total packets to send are 10 on A Client, where Server is receiving and
forwarding DOUBLE the size of packets to B client.
Even Text file is getting corrupted at B client side.
Pls help