Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to send files (mp3, images) using networking command?

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 3rd Apr 2015 16:04
Lets say I established a multiplayer connection with my friend.
Both of us are using an app that I made, istalled in our phones.
Is the any way to send files, for example mp3, or images, to one another in AGK2?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Apr 2015 20:13
A long time ago, I sent images by opening the file, reading the raw data and sending. At the other end, I wrote it back to a file. With Png files I found I could do it with DWords, and extra bytes were just ignored.

There may be easier ways now that I'm not aware of.

Quidquid latine dictum sit, altum sonatur
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 4th Apr 2015 20:42
I see. In AppGameKit, what command did you use for that? There doesn't seems to be a 'create file' or 'send file' commands..
What should I use for creating the empty file for those info to be written into?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Apr 2015 00:17
This is how I did it, I'm positive there are easier ways. Here's the send function (some of the commands are my own functions. I am not claiming this is easy to understand, I am just posting it or reference:




And here is the receive function:



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 5th Apr 2015 00:23 Edited at: 5th Apr 2015 00:28
Hello,

You can read the data from an Image wich are red,green,blue and alpha for an .png file.
Then send it to the other phones using the multiplayer commands,
where you extract them and convert the recieved data into a .png file again.

To read the data from an image you could make a memblock from it.

Make a Memblock: http://www.appgamekit.com/documentation/Reference/Memblock/CreateMemblockFromImage.htm
Read the Memblock: http://www.appgamekit.com/documentation/Reference/Memblock/SetMemblockByteSigned.htm
Send the Data: http://www.appgamekit.com/documentation/Reference/Multiplayer.htm

Receive the data and make an image from the memblock you wrote.


And you culd create an empty file with OpenToWrite()
There are no send file commands.


[Edit]I suggest BatVinks method now[/Edit]


Using AppGameKit V2 Tier1
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Apr 2015 01:23
Quote: "[Edit]I suggest BatVinks method now[/Edit]"


I think your method is better, I didn't have Memblocks when I wrote mine.

Baxslash pointed out in another thread that reading a file character by character is really slow. Loading the file into a memblock should make it faster.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 5th Apr 2015 14:06
Thank you guys. I can't believe I missed those commands.
With these, my project is back on the roll again (hopefully)
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 8th Apr 2015 14:10
One more thing, is there any limit to the size of Network Message that we can send in one go with CreateNetworkMessage()?

Because the max memblock size is 100,000,000, so a file larger than that would need to be broke down into smaller pieces if we use memblock to send and get a file.

Is there a limit to size of Network Message that we can send in one go with CreateNetworkMessage()?
If there are no size limit, then I can just send the file, and rewrite the data in one go to 1 single file.
If there are limits, then I'll have to break down the file. So maybe using memblock is more suitable since its cleaner
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Apr 2015 14:32
You'll see in my code above I broke it down into 256 byte chunks. The size is arbitrary, I have no idea why I chose it! But with this method, the data transfer doesn't care about the full size of the file.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 8th Apr 2015 14:53
I see.
I think sending the file in one go is more bandwidth friendly, but dividing them into chunks might be safer.

Is there a significant difference in data consumption between sending them in one go and sending them in small chunks?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Apr 2015 15:52
I don't know, but I would probably increase the 256 I used to something more reasonable, like 4,096 or 8,192.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 8th Apr 2015 16:03
Network packet size is usually 1500 bytes due to the hardware used. If the OS is given a packet larger than that, it will chop it up into multiple packets.

Login to post a reply

Server time is: 2024-11-25 20:22:54
Your offset time is: 2024-11-25 20:22:54