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