VB Code:
  1. 'Client Code
  2. Dim NF As Integer
  3. Dim file As String
  4.  
  5. Private Sub Command1_Click()
  6. CommonDialog1.ShowOpen
  7. Text1.Text = CommonDialog1.FileName
  8. End Sub
  9.  
  10. Private Sub Command2_Click()
  11. Winsock1.Connect "127.0.0.1", 6000
  12. End Sub
  13.  
  14. Private Sub Command3_Click()
  15. NF = FreeFile
  16. Open CommonDialog1.FileTitle For Binary Access Read Lock Read As #NF
  17. Do While (Loc(NF) < LOF(NF))
  18. DoEvents
  19. file = Input(4096, NF)
  20. If Winsock1.State = sckConnected Then
  21. Winsock1.SendData file
  22. End If
  23. Loop
  24. Close #NF
  25. End Sub
  26.  
  27. 'Server Code
  28.  
  29. Dim WF As Integer
  30. Dim dat As String
  31. Private Sub Form_Load()
  32. Winsock1.LocalPort = 6000
  33. Winsock1.Listen
  34. End Sub
  35.  
  36. Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
  37. If Winsock1.State <> sckClosed Then Winsock1.Close
  38. Winsock1.Accept requestID
  39. End Sub
  40.  
  41. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  42. Winsock1.GetData dat, vbString
  43. If received = 1 Then
  44. WF = FreeFile
  45. Open App.Path & "\Test.jpg" For Binary As #WF
  46. End If
  47. Put #WF, received, dat
  48. received = received + Len(dat)
  49. If received >= Len(dat) Then
  50. Close #WF
  51. End If
  52. 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:
Bad file name or number
I tried to fix the problem by putting:
VB Code:
  1. received = 1

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.