Search Unity

Add additional quality of service channel modes to NetworkManager

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

  1. kenmarold

    kenmarold

    Joined:
    Jun 11, 2015
    Posts:
    27
    I need to add a few additional quality of service channel modes to NetworkManager and I'm attempting to do it in this way:

    Code (CSharp):
    1.  NetworkManager netMan;
    2.  
    3.     void Start () {
    4.     ConnectionConfig cc = new ConnectionConfig();
    5.  
    6.     reliableChannel = cc.AddChannel(QosType.Reliable);
    7.     reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
    8.     reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
    9.     unreliableChannel = cc.AddChannel(QosType.Unreliable);
    10.     unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
    11.     cc.PacketSize = 1440;
    12.  
    13.     netMan.connectionConfig = cc;
    14.     }
    But I'm getting the error : `Property or indexer 'NetworkManager.connectionConfig' cannot be assigned to -- it is readonly`

    If the property is read-only then what is the proper way to create additional channels to NetworkManager?

    ...full function below


    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.         NetworkManager netMan;
    12.  
    13.         private int reliableChannel;
    14.         private int reliableSeqChannel;
    15.         private int reliableFragChannel;
    16.         private int unreliableChannel;
    17.         private int unreliableSeqChannel;
    18.  
    19.         // Use this for initialization
    20.         void Start () {
    21.  
    22.             ConnectionConfig cc = new ConnectionConfig();
    23.  
    24.             reliableChannel = cc.AddChannel(QosType.Reliable);
    25.             reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
    26.             reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
    27.             unreliableChannel = cc.AddChannel(QosType.Unreliable);
    28.             unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
    29.             cc.PacketSize = 1440;
    30.  
    31.             netMan.connectionConfig = cc;
    32.  
    33.             NetworkManager.singleton.StartHost();
    34.             Debug.Log("Server Started.");
    35.         }
    36.  
    37.         public void SendOnButtonPress()
    38.         {
    39.             SendTexture(textureToSend, messageToSend);
    40.         }
    41.  
    42.         //Call to send the Texture and a simple string message
    43.         public void SendTexture(Texture2D texture, string message)
    44.         {
    45.             TextureMessage msg = new TextureMessage();
    46.          
    47.             //Convert Texture2D to byte array
    48.  
    49.             msg.textureBytes = texture.GetRawTextureData();
    50.             msg.message = message;
    51.  
    52.             NetworkServer.SendToAll(MyMsgType.texture, msg);
    53.         }
    54.     }
    55.  
     
    Last edited: Oct 18, 2017
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    AFAIK you can do this via Inspector without any code. Tick Advanced Configuration checkbox.