|
-
Aug 2nd, 2008, 08:37 AM
#1
Thread Starter
Member
Winsock - Transfer File
I'm trying to transfer a simple file between a client and a server but It doesnt work... The sended file (ceta1.exe) must be 16kb but Its only 8kb.
I tryed to debug and I saw that the server use the Put function only 2 times.
What can be the problem?!
CLIENT:
Code:
Private Sub Command1_Click()
Winsock1.Close
Winsock1.Connect Text1.Text, Text2.Text
End Sub
Private Sub Command2_Click()
Dim datatosend As String
Dim conteggio As Long
datatosend = Space(4000)
Open Text3.Text For Binary As #1
For conteggio = 0 To CLng(LOF(1) / 4000)
Get #1, conteggio * CLng(4000) + 1, datatosend
Winsock1.SendData datatosend
Next conteggio
Close #1
End Sub
Private Sub Command3_Click()
cmn1.ShowOpen
Text3.Text = cmn1.FileName
End Sub
Private Sub Form_Load()
Text1.Text = Winsock1.LocalIP
End Sub
SERVER:
Code:
Private Sub Form_Load()
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
Open "C:\ceta1.exe" For Binary As #1
Put #1, , data
Close #1
End Sub
P.S. I know that there are a lot of topics and sources on the forum about this but I want to do it by myself because the other programs are too complicated
Last edited by LoopUntil; Aug 2nd, 2008 at 09:26 AM.
-
Aug 7th, 2008, 10:31 AM
#2
Re: Winsock - Transfer File
What version of VB are you using?
-
Aug 7th, 2008, 12:17 PM
#3
Thread Starter
Member
Re: Winsock - Transfer File
 Originally Posted by chris128
What version of VB are you using?
VB 6.0 , you can see it in my profily anyway xD
-
Aug 7th, 2008, 12:19 PM
#4
Re: Winsock - Transfer File
 Originally Posted by LoopUntil
VB 6.0 , you can see it in my profily anyway xD
lol sorry, I (like most people) dont check out the profile of every person that asks a question :P
I'm afraid I cant really help though cos I've only used VB.NET, not Vb6. Sorry, hope someone else can help you out.
-
Aug 7th, 2008, 06:12 PM
#5
Re: Winsock - Transfer File
Your sending loop is incorrect. For a 4000 byte file you'll try to do two 4000 byte reads. You should also do a sequential (not random) read in the loop.
You also need to deal with a final chunk < 4000 bytes.
Your receive logic is incorrect. It accepts one received data segment and then gives up. Typically these are about 8K bytes when receiving a steady stream. You have to receive/write in chunks as they arrive, until the final chunk.
You have provided no method to determine when a final chunk has arrived.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|