need help with downloading a file with TStream
BlitzMax Forums/BlitzMax Programming/need help with downloading a file with TStream
| ||
Iīve tried the code from this post: Code archieves Is anyone out there to help with this? It doesnīt work straight ahead in BMAX, am I right? Especially ReadBytes isnt a plain function, a method instead...but I found no explanations. I work with TSockets and the connection is fine. I donīt use any Streamfunctions from this example, except from buffer = CreateBank(max_download_byte) downward part of my code: Global Host_IP= iptointeger(HostStream) tcpsocket = CreateTCPSocket:TSocket() tcpstream = CreateSocketStream:TSocketStream( tcpsocket) tcp = ConnectSocket( tcpsocket,Host_IP,80) stream:TStream = OpenStream(tcpstream) WriteLine stream, "GET /images/towercam.jpg HTTP/1.1" WriteLine stream, "HOST: ***.***.***" I got all responses with readline, but fail with get a picture file and save it. This part from the archive wonīt work: buffer = CreateBank(max_download_bytes) While Not Eof(stream) Size = ReadBytes(buffer, tcp, 0, max_download_bytes) WriteBytes(buffer, file, 0, Size) |
| ||
I have solved it by myself, maybe not the best solution. I read and write byte by byte form the stream and the file is a real picture! :) :) :) Local response$ Repeat response$=ReadLine(stream) Print "-> "+response$ Until response$="" Delay(2) Local name$ = CurrentDate()+"_"+CurrentTime() name$ = Replace(name$,":","-") name$ = Replace(name$," ","") Local file:TStream=WriteFile(target_path$+name$+".jpg") If Not file Then Print "nix File" End Print "Fileopen...." While Not Eof(stream) WriteByte(file,ReadByte(stream)) Wend CloseFile(file) |