0
我在發送大約1.5 mb的圖像文件時遇到了網絡問題。我已經配置NetworkManager使用QoSType ReliableFragmented,但它顯然不工作。我究竟做錯了什麼?附加的NetworkManager組件的代碼和屏幕截圖。儘管將ReliableFragmented通道分配給網絡管理器,但緩衝區仍然太大錯誤
我receving的錯誤是:
NetworkWriter WriteBytes: buffer is too large (1699064) 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()
代碼啓動網絡和串行數據
TextureMessage.cs
using UnityEngine.Networking;
public class TextureMessage : MessageBase
{
public byte[] textureBytes;
public string message; //Optional
}
MyMsgType.cs
using UnityEngine.Networking;
public class MyMsgType
{
public static short texture = MsgType.Highest + 1;
}
硒rver.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Server : MonoBehaviour {
public Texture2D textureToSend;
string messageToSend = "Test Message";
// Use this for initialization
void Start()
{
NetworkManager.singleton.StartHost();
Debug.Log("Server Started.");
}
public void SendOnButtonPress()
{
SendTexture(textureToSend, messageToSend);
}
//Call to send the Texture and a simple string message
public void SendTexture(Texture2D texture, string message)
{
TextureMessage msg = new TextureMessage();
//Convert Texture2D to byte array
msg.textureBytes = texture.GetRawTextureData();
msg.message = message;
NetworkServer.SendToAll(MyMsgType.texture, msg);
}
}
的可能的複製[NetworkWriter WriteBytes:緩衝器過大(https://stackoverflow.com/questions/46802301/networkwriter-writebytes-buffer-is-too-large) – Draco18s