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 / Share media (images) over LAN using Multiplayer?

Author
Message
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 31st Oct 2018 10:48
Is it at all possible?

What I want to achieve is having my LAN Host App share a set of 4 small images that the client request and receive.

I could 'cheat' and have all the clients just receive a string with the ID of the image file from the Host, and then proceed to hit my API and download from there. But that would mean that there will be potentially up to 30x4=120 hits to the server blitzing it within a second or two - from the same outbound IP which may trigger DDoS protection on my API - and it makes one reliant on all clients having internet access - not just the host - and its' bandwith limit. Which is significantly lower than LAN over WiFi...
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 31st Oct 2018 12:36 Edited at: 31st Oct 2018 12:46
Yes, no problem at all.
But you need to split the image in multiple packets, in order to keep the network bandwith stable.


First you need to know how to copy files byte for byte:



Now the idea is, to read the image as some chunks of bytes and then post the byte sequence over the net. (Sort of sourceFile)
The other side just merges the bytes to a new file. (like destFile, in the example)
Keep in mind, that you will have to build some sort of recieve Buffer array, because the media can be corrupted if a package wont be recieved.

So you got an array with byte chunks and chunk[34] is empty for example when you finished the recieve process, so you need to request the byte from chunk[34] again, to get a full working media file.

Process:
1. Connect to server
2. Request media file
3. Server sends amount of bytes for the media file (and also the chunk size)
4. Client creates buffer array based on the amount of bytes.
5. Server starts sending chunks of byte data including a header identifier for the buffer array (the chunk size is dependent on the maximal amounts of bytes per networkmessage, and the network bandwith)
6. Client saves chunks into buffer array
7. Once the last chunk is sent, the client checks for integrity (are all bytes recieved, is every array chunk filled?)
8.1. If not, then the client requests a specific missing chunk
8.2 If yes, the file transfer is completed, the media file can be saved from the buffer array.
9. Finished

If you got really small .jpg images, and a stable network, you won't need a recieve buffer.
Only if you want to go big...

[/url]
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 1st Nov 2018 09:46 Edited at: 1st Nov 2018 09:54
That makes sense - but with the built in Multiplayer-Messages commands, there is only the option to send integer, float and string. To send bytes, I'd have to employ sockets. Which will be a new and wonderful exploration trip that I can't just plug into my existing project, but have to make a proof-of-concept demo app just to get my head around it

Oh, and the images I want to transmit are quite small. All are 256x256 pixels in PNG format. Ranging from 2kb to ~200kb, with the vast majority being smaller than 30kb.

Also, since I use port 1025 for sending Messages (using hostNetwork() command), would I need to use another port for sockets (using the createSocketListener() command)?
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 1st Nov 2018 11:36
Just send integers then
RGBA fits perfectly into an integer
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 1st Nov 2018 13:11 Edited at: 1st Nov 2018 13:20
You can use this example to get four bytes into one integer, and back.
Also good, to set the client IP adress to a network integer



You need to keep count, as your desired byte amount could be smaller that four, most of the time in the last package.

Buut you could also try the strings! Each string char can contain 256 possible settings. Chr(byte) with you strings maybe

[/url]
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 4th Nov 2018 11:25 Edited at: 4th Nov 2018 11:30
How many pictures do you have? Do you generate them on the fly?

Mabe the easiest way is, to have the pictures at the client from the beginning. Or can the client change his picture without your knowing?
If it's Avatars, maybe you provide 100 pictures and have only to send the ID of the image, but without downloading it to the client, because the client has already the pictures and can easily switch between.

You also could think about chunks, like JPEGs, they are stored in 8x8 chunks. And maybe your 256 x 256 Pixel picture is only a combination of a bunch of chunks. so that would be 32 x 32 * (8 x 8)

Or!!!

You could use Base64 encoding, and use the String-commands again.


-->>>> Bytestream (file) --> Encode to Base64 string
--> send the String via Network
---> get the String and Decode the Base64 string to a file or MemBlock


https://www.motobit.com/util/base64-decoder-encoder.asp


AGK has no Base64-String-To-File or to MemBlock-command yet, but I guess, we could build one.
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 4th Nov 2018 13:35 Edited at: 4th Nov 2018 13:36
If this is LAN and everyone receive the same , perhaps check broadcast , so you only sent it once and everyone receives it in the same packets , would really limit the network traffic needed

https://www.appgamekit.com/documentation/Reference/Multiplayer/CreateBroadcastListener.htm
Subscribe and checkout great AppGameKit video's here: Videos click here
Latest GameGuru Loader news: News click here
Get GameGuru Loader PBR version here: Steam click here
best regards Preben Eriksen,
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 5th Nov 2018 12:41
If you go for the Broadcast Listener, you really need to check all packages on integrity, because its UDP and you cant be shure about all packages. Well actually TCP should also need it - because of experience.

[/url]

Login to post a reply

Server time is: 2024-11-23 11:59:53
Your offset time is: 2024-11-23 11:59:53