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: 55064
Latest: sla mano ninja
New This Month: 0
New This Week: 0
New Today: 0
Stats
Total Posts: 55834
Total Topics: 3271
Most Online Today: 2321
Most Online Ever: 16063
(June 06, 2025, 06:06:01)
Users Online
Members: 0
Guests: 2167
Total: 2210
Google (AdSense) (2)
Google (12)
Baidu (29)

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

Girls In Your Town - No Verify - Anonymous Casual Dating by MateQ
January 19, 2026, 21:08:21

Microphone-voice support. by mamita
January 11, 2026, 05:33:03

Targeting ShadowBlur. by mamita
January 11, 2026, 05:31:16

Should The Recall function be removed? by mamita
January 11, 2026, 05:24:41

Character Appearances + Outfit Creator by mamita
January 11, 2026, 05:21:56

Shinobi Life Online Sword Combat System by mamita
January 11, 2026, 05:19:13

Last name by mamita
January 11, 2026, 05:13:39

Summoning by mamita
January 11, 2026, 05:07:23

Jutsus that are in the anime manga like kage bunshin/water dragon/flame ball etc by mamita
January 11, 2026, 05:03:48

deeper diplomatic system :) by mamita
January 11, 2026, 04:54:56

Top Posters

Mars
Posts: 2637
Reminance
Posts: 2232
Shivraj
Posts: 1610
m4r1us
Posts: 1298
Manuster
Posts: 1265
NinjaMirage
Posts: 1165
Nova
Posts: 1139
taigakun
Posts: 1091
Fraudulent
Posts: 1084
Konohuro
Posts: 1056