0

I am using a modification of code posted by Moose located at https://stackoverflow.com/a/566477/5061596 to do a WebRequest to send a binary file to a device. I've modified it for vb.net as such:

Dim updateFile() As Byte = File.ReadAllBytes(myUpdateFile)
Dim request As HttpWebRequest = HttpWebRequest.Create(myUpdateFileURL)
request.Method = "POST"
request.Timeout = 300000  ' 5 minutes
request.ProtocolVersion = HttpVersion.Version10
request.Credentials = myCredentials
request.ContentLength = updateFile.Length
request.ContentType = "application/octet-stream"

Dim stream As Stream = request.GetRequestStream
stream.Write(updateFile, 0, updateFile.Length)
stream.Close()

This code is working fine but it seems httpWebRequest is in general "slow" and some of the devices I'm working with are 10Mb Ethernet connections. Those two items combined is giving me 2 - 2:30 minute uploads on 100Mb files. For this reason I would like to implement some type of feedback. Is there a easy way to modify this code for status? I would think so since I know the file length already. The problem is each time I try to modify it to loop through chunks of the file being uploaded I'm doing something wrong which is, for lack of better terms, destroying the file and the receiving device rejects it.

ADY
  • 101
  • 1
  • 9
  • The HTTP protocol in general is rather slow (perhaps not as slow as in your example, but definitely slower than merely using TCP). Unless the other device requires you to use HTTP, switching to TCP would be a much better choice (though you're gonna have to implement your own message framing). – Visual Vincent Jan 18 '18 at 20:50
  • I'm exactly not sure how these machines/devices are connected, but do note that they must be in the same LAN in order to be able to utilize the speed of the Ethernet connection. – Visual Vincent Jan 18 '18 at 20:52
  • This guy wrote a wrapper around a stream object to handle this - would it work for you? http://mel-green.com/2010/01/progressstream/ – GMan80013 Jan 18 '18 at 21:26
  • Yes the device requires HTTP, yes they are on the same LAN (usually directly connected actually). I will look into the stream wrapper and see if it will work. Thanks. – ADY Jan 19 '18 at 21:13

0 Answers0