我无法通过我的网络发送大约 1.5 mb 的图像文件。我已将 NetworkManager 配置为使用 QoSType ReliableFragmented,但它显然不起作用。我究竟做错了什么?附上 NetworkManager 组件的代码和屏幕截图。
我收到的错误是:
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()
启动网络和序列化数据的代码
纹理消息.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;
}
服务器.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);
}
}