Search Unity

Getting Writebytes error despite assigning ReliableFragmented channel to Network Manager

Discussion in 'Multiplayer' started by kenmarold, Oct 18, 2017.

  1. kenmarold

    kenmarold

    Joined:
    Jun 11, 2015
    Posts:
    27
    I'm having trouble with sending an image file that's around 1.5 mb across my network. I thought that I had configured NetworkManager correctly but apparently not. What am I doing wrong? Code and screenshot of NetworkManager component attached.

    The error I'm receving is:

    NetworkWriter WriteBytes: buffer is too large (699064) bytes. The maximum buffer size is 64K bytes.
    UnityEngine.Networking.NetworkWriter:WriteBytesFull(Byte[])
    TextureMessage:Serialize(NetworkWriter)
    UnityEngine.Networking.NetworkServer:SendToAll(Int16, MessageBase)
    Server:SendTexture(Texture2D, String) (at Assets/Scripts/Server.cs:41)
    Server:SendOnButtonPress() (at Assets/Scripts/Server.cs:28)
    UnityEngine.EventSystems.EventSystem:Update()

    NetManScreenShot.jpg

    Code to start network and serialize data

    Code (CSharp):
    1. using UnityEngine.Networking;
    2.  
    3. public class TextureMessage : MessageBase
    4. {
    5.     public byte[] textureBytes;
    6.     public string message; //Optional
    7. }
    Code (CSharp):
    1. using UnityEngine.Networking;
    2.  
    3. public class MyMsgType
    4. {
    5.     public static short texture = MsgType.Highest + 1;
    6. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class Server : MonoBehaviour {
    7.  
    8.     public Texture2D textureToSend;
    9.     string messageToSend = "Test Message";
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.         NetworkManager.singleton.StartHost();
    15.         Debug.Log("Server Started.");
    16.     }
    17.  
    18.     public void SendOnButtonPress()
    19.     {
    20.         SendTexture(textureToSend, messageToSend);
    21.     }
    22.  
    23.     //Call to send the Texture and a simple string message
    24.     public void SendTexture(Texture2D texture, string message)
    25.     {
    26.         TextureMessage msg = new TextureMessage();
    27.        
    28.         //Convert Texture2D to byte array
    29.  
    30.         msg.textureBytes = texture.GetRawTextureData();
    31.         msg.message = message;
    32.  
    33.         NetworkServer.SendToAll(MyMsgType.texture, msg);
    34.     }
    35. }
     
  2. juntoalmar

    juntoalmar

    Joined:
    Dec 7, 2018
    Posts:
    6
    Hi,
    I'm having the same issue trying to send a texture through the network, as it's bigger than 64k. Did you solve it?
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Application level fragmentation is a workaround to this. This is a UNET limitation that was put in place.