Loading an image over the network

Monkey Forums/Monkey Programming/Loading an image over the network

frank(Posted 2012) [#1]
Does anyone have any code to load an image over the network? For instance with mnet? If possible resulting in a standard Image object ?


AdamRedwoods(Posted 2012) [#2]
not that i've seen, but you could write your own. do you mean through http?


frank(Posted 2012) [#3]
Well the only networking lib for monkey so far which is cross platform is http right? So that's the way to go I guess; sockets would be fine but we don't have that do we?


AdamRedwoods(Posted 2012) [#4]
tcp is in the BRL folder for Monkey V66.

Yes theres mnet, but doesn't look like it handles MIME/binary (and doesn't seem to handle OSX, Linux). You can base64 the images and request the text file, that would work through mnet.


frank(Posted 2012) [#5]
Thanks! For the game i'm making I need transparant file handling across platforms; seems that the current file stuff in Diddy etc is not really what i'm looking for; I need to be able to just get/save files locally on desktops/browsers and in the 'filesystem' equivalent of mobiles. Correct me if i'm wrong but that's not there right? What would be a good way going about that; I don't mind writing it myself but I don't want to do double work and I would like for other people to benefit as well. Seems networking and file io are 2 things partially lacking or maybe I missed something.


smilertoo(Posted 2012) [#6]
I wouldn't recommend it for any mobile game.


AdamRedwoods(Posted 2012) [#7]
I need to be able to just get/save files locally on desktops/browsers and in the 'filesystem' equivalent of mobiles


brl.filestream is there for desktop and mobile but not for html5 or flash (due to obvious security reasons).


frank(Posted 2012) [#8]
Yes, but unfortunately if you want to make something transparent for all targets it needs to be , well, transparent :) I think there would be no problem making something abstract around websockets for the HTML5 / Flash versions. And it would be also feasible to make a file system abstraction around HTTP for HTML5/Flash and native storage for the rest. Makes a lot more sense (in my eyes at least :) than having limp/partial targets.

For HTML5 (I don't know Flash and probably won't use it, but who knows, I'll check that later), it seems to make sense to make a Node.js (or PHP, or whatever; doesn't matter) script on the server which takes in a session variable (aka, the current user) and uses .htaccess and to fake a xxx.build/data directory contents. So you can do something like: /Dir?session=123 and get the contents of the data dir for that user. Then simply do /xx.build/data/SOMEFILE which returns actually that file from /xx.bind/data/SESSIONID/SOMEFILE (or better, in a safer location which you cannot reach from the outside, but that's trivial). That way you can make a FileSystem object for monkey which works the same for media files as the rest. Saving of files the same idea; for HTML5 you need to use some native stuff to show the upload field in, for instance, junglegui but other than that it seems this all can work almost the same on all platforms instead of hacking it. But maybe it just works for my use case :) I'm implementing this anyway.