Important News

We have released Shinobi Life Online Pre-Alpha Version 1.1.0.0! This update features Earth Release: Earth Dome Jutsu, Aiming Mode and more! Try it out and tell us what you think.

User

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

Discord

Statistics

Members
Total Members: 56202
Latest: Snowsfright
New This Month: 36
New This Week: 0
New Today: 0
Stats
Total Posts: 55825
Total Topics: 3340
Most Online Today: 1567
Most Online Ever: 16063
(June 06, 2025, 06:06:01)
Users Online
Members: 1
Guests: 1090
Total: 1099
Sadaiyan974
Google (AdSense)
Google (7)

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - peterp

Pages: [1]
1
Programming / Downloading image data from server to client
« on: March 07, 2016, 16:33:18 »
Syntax is Unity3d C#, networking is UNET.
This is useful for uploading and downloading images, for example custom clan banners etc.

Server side
Code: [Select]
const short DOWNLOAD_FILE = 1337;
void SendImageToClient(string path,int size, int connID)
{
    if (File.Exists(path))
     {
         byte[] fileData = File.ReadAllBytes(path);
         Texture2D tex = new Texture2D(size, size);
         tex.LoadImage(fileData);

          FileMessage fmsg = new FileMessage();
          fmsg.name = path;
          fmsg.size = size;
          fmsg.data = tex.EncodeToPNG();

         NetworkServer.SendToClient(connID, DOWNLOAD_FILE, fmsg);

     }
   
}
public class FileMessage : MessageBase
{
    public string name;
    public byte[] data;
    public int size;
}



[b]Client side[/b]



Code: [Select]
const short DOWNLOAD_FILE = 1337;
void Start()
{
    myClient.RegisterHandler(DOWNLOAD_FILE, OnDownloadFile);
}

void OnDownloadFile(NetworkMessage msg)
{

        FileMessage wmsg = msg.ReadMessage<FileMessage>();

        Texture2D tex = new Texture2D(wmsg.size, wmsg.size);
        tex.LoadImage(wmsg.data);
        //Do something with the downloaded image
}

Pages: [1]

Recent Topics

Zen'no no Sabaku-House of Kings by mamita
August 09, 2025, 13:29:12

Tsukegami Clan by mamita
August 08, 2025, 18:19:17

The Himitsu Clan by mamita
August 08, 2025, 17:55:04

Raiu by mamita
August 08, 2025, 17:42:09

The Tsunagami Clan by mamita
August 08, 2025, 17:40:06

Kitsune no Sabaku - Nomads of the Desert by mamita
August 08, 2025, 17:09:57

Experiences with Car Theft Insurance in South Side vs. North Side by mamita
August 07, 2025, 06:19:34

The Shintino Clan by mamita
August 07, 2025, 06:17:01

The Nii clan by mamita
August 07, 2025, 06:15:52

The Yamazaki Clan by mamita
August 07, 2025, 06:10:00

Top Posters

Mars
Posts: 2638
Reminance
Posts: 2233
Shivraj
Posts: 1610
m4r1us
Posts: 1298
Manuster
Posts: 1267
NinjaMirage
Posts: 1165
Nova
Posts: 1140
taigakun
Posts: 1094
Fraudulent
Posts: 1086
Konohuro
Posts: 1056