VB Code:
'Client Code
Dim NF As Integer
Dim file As String
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Winsock1.Connect "127.0.0.1", 6000
End Sub
Private Sub Command3_Click()
NF = FreeFile
Open CommonDialog1.FileTitle For Binary Access Read Lock Read As #NF
Do While (Loc(NF) < LOF(NF))
DoEvents
file = Input(4096, NF)
If Winsock1.State = sckConnected Then
Winsock1.SendData file
End If
Loop
Close #NF
End Sub
'Server Code
Dim WF As Integer
Dim dat As String
Private Sub Form_Load()
Winsock1.LocalPort = 6000
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData dat, vbString
If received = 1 Then
WF = FreeFile
Open App.Path & "\Test.jpg" For Binary As #WF
End If
Put #WF, received, dat
received = received + Len(dat)
If received >= Len(dat) Then
Close #WF
End If
End Sub
How can I be sure it is sending data all the time? I tried the above code and I get a message on the server saying:
I tried to fix the problem by putting:
Before the first if statement in the data arrival event but when I send files the output size on the server end is alway 4096bytes.
That is for every file not just the files that are suppose to be that size.