Question

Blitz3D Forums/Blitz3D Programming/Question

Caton(Posted 2015) [#1]
Is there anyway you can load a file from a url?


Matty(Posted 2015) [#2]
Yes.

Look at the tcp ip command reference. Have a look at the example.

If you know the url to the file you want you can simply write the output of the http response to a file on the local machine or directly into memory such as in a bank or similar.


Caton(Posted 2015) [#3]
not sure how to directly into memory.
could tell me how to do that?


Matty(Posted 2015) [#4]
Well....instead of passing the output to a file stream pass it to a bank.

Check up the bank and file stream examples in the docs - they are quite easy to follow and cover pretty much everything you are asking.


Caton(Posted 2015) [#5]
how will load sound or models or other resources?


Caton(Posted 2015) [#6]
using bank


Matty(Posted 2015) [#7]
Standard blitz commands won't load sound from a bank. There may be libraries that do this though.

Non animated models can be recreated (with the addvertex,addtriangle,create surface) commands from data at runtime.

Standard blitz commands won't create animated models at runtime either (not bone or md2 anyway) - however once again a library may exist for this.

Alternatively - you could save them to disk temporarily, then load the models and sounds into memory before removing them again.


ThePaiva(Posted 2015) [#8]
Actually, you can play a sound directly from an URL using PlayMusic(url) and control it using the channels functions.


bytecode77(Posted 2015) [#9]
I actually provided one in the code archives some time ago:

http://www.blitzbasic.com/codearcs/codearcs.php?code=2279

It also supports downloading of chunked content, which is important if you want to retrieve PHP generated output.


Caton(Posted 2015) [#10]
Can I use open\read file from url?
without downloading the file?


bytecode77(Posted 2015) [#11]
In my example, the content gets downloaded. But I guess you could adapt the code so it works for just reading text.

Please note, that chunked reading is very important! PHP scripts which have a runtime above a certain threshold will always yield chunked output.


Caton(Posted 2015) [#12]
in tcp how do I send a text?
when I type hello world! in input command?
the game displays the text like text,0,0,txtstring$
from tcp game server.


bytecode77(Posted 2015) [#13]
That's a pretty vague question. Is your game HTTP based in any way? If so, you would have to do a HTTP post request.

If your game is peer to peer based and using plain TCP, then it's pretty simple.

WriteString(tcpStream, "Hello World")


Otherwise, if you want a more defined answer, then please post a question containing all relevant details.


Caton(Posted 2015) [#14]
How do I load a txt file with tcp
I am loading a database user file as txt file
how would I do this?


Caton(Posted 2015) [#15]
I want to write a text file to tcp game server and read text file from tcp game server.


Caton(Posted 2015) [#16]
I need help how do I run .bb file with blitzcc with batch script?


ThePaiva(Posted 2015) [#17]
To load a txt file, use the code from the link bytecode77 provided, then just read it using readfile$(filename$) and then the read functions...

About sending a text file to the game server, I think it would be easier to send chunks of it as a TCP message and read them at the game server when you receive them.

About running them with batch script, not sure, but I think blitzcc.exe accepts a file as a command line, try something like " blitzcc.exe filename$ "