You can send files of ANY size with this (well actually any file less than 2GB).
First start the Server program, click on the "Start Listening for Connections" button.
Then start the client, choose a file you want to transfer, then click on "Send File"
The server supports multiple connections, so you can open more than one Client application and transfer more than one file.
Both of them show the progress of the transfer.
The server saves the files in its App.Path directory.
I tried to make it as simple as possible, and I did not put any comments.
I have a few comments, but that's because I copied and pasted some code from my other applications.
Anyways... enjoy... and I hope you learn something from it.
Last edited by CVMichael; Dec 21st, 2005 at 01:34 PM.
Reason: Some spelling mistakes
Re: VB - How to send a file using the Winsock control
Yea, I have cable modem too but it's 128 KBits / second Upload and 1 MBit/second download.
If you notice the values are in Bits, so you have to divide by 8 to get Bytes...
So really it's 16 KBytes/second upload, and 128KBytes/second download.
Re: VB - How to send a file using the Winsock control
You have 1 Mbit/s. 256KB/s is just the double of yours...
Yeah, thats right. Today almost everyone in a "1st-world country" has got at least DSL.
Actually i have unfortunately just 384 kbit/s (48 KB/s) because my (DS)-Line is much too long (over 50 db). That really isn't fast.
I reached the 256 KB/s on my local Computer.
Re: VB - How to send a file using the Winsock control
And by the way, about this:
VB Code:
Private Const PacketSize As Long = 1024 * 31
You are wondering why you cannot multiply by 32 ?
That's because 1024 is taken as Integer by the compiler, and 32 is also an integer, so if you multiply them together you also get integer type, but you get an overflow error, right ?
The solution is simple, comvert the numbers to Long type, like this:
VB Code:
Private Const PacketSize As Long = 1024[B]&[/B] * 64[B]&[/B] ' 64 KBytes buffer
Or if you just type in the total number (multiplied), then it will automatically convert it to long type
VB Code:
Private Const PacketSize As Long = 65536 ' 64 KBytes buffer
Re: VB - How to send a file using the Winsock control
Originally Posted by CVMichael
That is KBytes/Second, so you reached 1984 KBytes / second that is 31,744 KBits / second !!!!
The program shows the speed in KBytes / second !
You divided KBytes by 8, but it already shows in KBytes...
No, I divided nothing.
1984/8= 248, My speed at the beginning was 256 Kbyte/s
The picture shows the speed AFTER my modification.
Before, the speed was 2048 Kilobit/s = 256 Kilobyte/s = 0,256 Megabyte/s = 0.000256 Gigabyte/s. Just to make sure that i know these things.
The hint with the "&" works fine! But the speed won't go over 10.000 kbyte/s
Last edited by DrGonzo; Nov 1st, 2006 at 09:44 AM.
Re: VB - How to send a file using the Winsock control
OMG, you have to learn your limits.... first of all, how on earth could you send 10 MBytes / second on a real internet connection ? Why would you want to transfer a file from your comptuer to the same comptuer using Winsock.... why not just copy & paste the file the regular way ?
And also, you said it won't go over 10 MBytes / sec ? well, do this:
Copy a file from a directory to another (on the same hard drive), and the speed won't be much faster than that...
The hard drive has to read 10 MBytes / second, and it has to write the same 10 MBytes back to the same hard drive, so your computer has to handle 20 MBytes / second !
Stop testing this on a local computer, and use a real internet connection ! and then you don't need to make the buffer that big because it cannot transfter that much anyways because of internet limitations....
Re: VB - How to send a file using the Winsock control
I've just tested the program. I'm now not going to use it for any file i will copy on my computer.
Did i anoy you with any of the above written? English isn't my mother tongue.
Re: VB - How to send a file using the Winsock control
If it's a Permission denied error, then there is nothing I can do/change in the program to fix that... only you can, by setting the appropriate permissions to the directory where you have the application
Re: VB - How to send a file using the Winsock control
Originally Posted by CVMichael
Yea, I have cable modem too but it's 128 KBits / second Upload and 1 MBit/second download.
If you notice the values are in Bits, so you have to divide by 8 to get Bytes...
So really it's 16 KBytes/second upload, and 128KBytes/second download.
My program shows the speed in KBytes / second...
You have one slow cable modem, then I topped mine out downloading off a good server at just over 2mb/s. I downloaded a 20 MB file in less than 10 seconds, in other words.
Re: VB - How to send a file using the Winsock control
Originally Posted by BrendanDavis
You have one slow cable modem, then I topped mine out downloading off a good server at just over 2mb/s. I downloaded a 20 MB file in less than 10 seconds, in other words.
How much do you pay per month ?
I can choose to have higher speed from my provider if I pay more (of course), I think the highest is about the speeds you just mentioned, but is aproximatelly $60 (Canadian $) here. Now I'm paying $30 per month.
Re: VB - How to send a file using the Winsock control
Hey I've modified your code and it became more effective in sending. you don't need to increase packet size to send faster. I've disabled the timer and found a workaround. Replace your SendComplete event with this:
VB Code:
Private Sub SckSendFile_SendComplete()
'Finish off the send complete first with DoEvents, then immediately send the data
DoEvents
Call tmrSendFile_Timer 'Send the data
End Sub
It have just used "DoEvents" rather than the timer. You should find that it sends a lot faster on fast networks like LAN (not limited to 256 KB/s) and does not need a timer. It should be only slightly faster over slower connections. The "DoEvents" really did work well for me.
Last edited by evan29; Feb 11th, 2007 at 07:12 AM.
Re: VB - How to send a file using the Winsock control
Hi!
I just wanted to say that nowadays in big cities for example here in germany like cologne or stuttgart VDSL with an effective download data rate of 50 Mbit/s (that are 6,25 Mb/s) and an upload data rate of 10 Mbit/s are very common. These cost 50 euro or 75 C $.
But even in german villages you can get ADSL or even ADSL2 and ADSL2+ with data rates up to 25 Mbit/s (3,125 Mb/s).
Re: VB - How to send a file using the Winsock control
Let's say you are a car repair man, and someone comes to you and tells you fix my car, it does not work... will you know what to fix ? will you know where to even start checking ?
But if if he tells you that the back right lights are not working, then you know where to start looking for problems, right ?
So... if you just tell me "i can't send files", how do you think I'll know where the problem is ?
And besides that... programs don't work the same way on every computer... a lot of things can iterfere with the program, firewall, router, antivirus, operating system, etc...
What did you try ?
What works, and what does not work ?
Tell me something usefull !
If you continue to ask for help like this... then it will take a hell of a lot of time to get your problem solved !
Re: VB - How to send a file using the Winsock control
Originally Posted by CVMichael
How much do you pay per month ?
I can choose to have higher speed from my provider if I pay more (of course), I think the highest is about the speeds you just mentioned, but is aproximatelly $60 (Canadian $) here. Now I'm paying $30 per month.
I pay $40 a month US. Don't know how much that is Canadian (even though I used to live there, lol). i think the exchange rate these days is .97 / dollar, or at least it was a week or two ago. so it's not THAT much more in canadian.
God put me on this earth to do many great things, and I'm so far behind that I'm going to live forever.
I'm programming for Windows using a Apple Mac Mini, 1.5Ghz with 512MB DDR RAM. I feel like I'm committing a crime :P
Re: VB - How to send a file using the Winsock control
Hi CVMichael,
for couples of weeks i have been trying to write a client/server application (1 server with multi-clients) which can send and receive files (bidirectional).
without success, until today i land on your article on this great site. my problem was to handle more than one client while sending/receiving files, but with ur example code i think my life become a bit easier, i will ask for help just in case i'm having difficulties.
pp
Last edited by ppitta; Sep 17th, 2007 at 08:27 AM.
Re: VB - How to send a file using the Winsock control
The coding is really amazing....but Im trying to do the other way around...
Is there anyway I can use this code to send file from one server to multiple clients instead from multiple clients to one server...actually I have connected multiple printing machines to a server and all the production files I would like to transfer from a server thru network. Total Clients I have 5 and I will be transferring multiple files to each machine. The size of the files will be 25 MB to 50 MB and I got attracted by your code since it can transfer any size of file.
Any help?
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Re: VB - How to send a file using the Winsock control
If you transfer through local network, then there is a much better solution...
Right now, (if you reverse), when you send a file that is 50 MBytes * 5 times, that will be 250 MBytes sent over the network.
But... if you use UDP connection, you can broadcast the file to ALL computers at the same time, therefore if you send 50 MB to 5 clients, you are sending only 50 MBytes over the network ! You don't even have to specify the target computer to send to, as long as there is a program listening on the port on the client computer, they will pick up the file.
But since it's UDP, you probaly also have to add a CRC (or something like that) to make sure (on the client side) that you received the entire file.
Re: VB - How to send a file using the Winsock control
If I use these forms in my two different projects (Client Form in one project and Server From in other project) Im getting Type Mismatch error at line FitTextInListView Me.lstConnections, 1, , K + 1 at the tmrStatus_Timer() at the ServerReceive Module
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Re: VB - How to send a file using the Winsock control
Originally Posted by CVMichael
If you transfer through local network, then there is a much better solution...
Right now, (if you reverse), when you send a file that is 50 MBytes * 5 times, that will be 250 MBytes sent over the network.
Yes, Im transferring thru the local network only (LAN)
I will be sending different set of files from the data process pc to each printing machine...that is for the Machine1, I will send the files for Job No. 1234, Machine2, I wll send the files for Job No. 1235 and so on...
I dont want to broadcast the files instead choosing some set of files to each machines based on the job number specified. And also I want to pass the information of the directory where it has to be stored.
Hope Im not confusing...If you want me to explain it more, I will do
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Re: VB - How to send a file using the Winsock control
Hi ganeshmoorthy,
I understand now... before I assumed you send the same file to all computers...
As I was saying before, right now I'm at work, and I don't have time, but hopefully I'll remember to make an example for you when I get home. I will probably add the example as a new thread in the CodeBank...
PS, how do you know what file to send to each computer appon connection ?