private void Start()
    {
        GlobalConfig globalConfig = new GlobalConfig();

        NetworkTransport.Init(globalConfig);

        //host topology
        ConnectionConfig connectionConfig = new ConnectionConfig();

        connectionConfig.AddChannel(QosType.Unreliable);

        HostTopology hostTopo = new HostTopology(connectionConfig, MAX_CONNECTIONS);

        //connecting to host
        winHostID   = NetworkTransport.AddHost(hostTopo, 0);
        channelType = QosType.Unreliable;

#if UNITY_WEBGL
        connectionID = NetworkTransport.Connect(winHostID:, SERVER_IP, SERVER_WEB_PORT, 0, out err);
#else
        connectionID = NetworkTransport.Connect(winHostID, SERVER_IP, SERVER_WIN_PORT, 0, out err);
#endif
        if (connectionID >= 0)
        {
            isConnected = true;
        }
    }
Beispiel #2
0
    public void SendJSONMessageToAll(string JSONobject, QosType type)
    {
        byte error = 0;

        byte[] messageBuffer = Encoding.UTF8.GetBytes(JSONobject);
        //Debug.Log("Sending message of length " + messageBuffer.Length);
        foreach (KeyValuePair <int, ClientInfo> client in _clients)
        {
            if (type == QosType.Reliable)
            {
                NetworkTransport.Send(client.Value.socketID, client.Value.ConnectionID, TCP_ChannelID, messageBuffer, messageBuffer.Length, out error);
            }
            else if (type == QosType.Unreliable)
            {
                NetworkTransport.Send(client.Value.socketID, client.Value.ConnectionID, UDP_ChannelID, messageBuffer, messageBuffer.Length, out error);
            }
            else if (type == QosType.UnreliableFragmented)
            {
                NetworkTransport.Send(client.Value.socketID, client.Value.ConnectionID, UDP_ChannelIDFrag, messageBuffer, messageBuffer.Length, out error);
            }
            else if (type == QosType.UnreliableSequenced)
            {
                NetworkTransport.Send(client.Value.socketID, client.Value.ConnectionID, UDP_ChannelIDSeq, messageBuffer, messageBuffer.Length, out error);
            }
        }
    }
 public void Send <T>(T data, MessageType type, QosType qosType = QosType.Unreliable)
 {
     byte[] objData = StructTools.RawSerialize(data);
     byte[] objType = BitConverter.GetBytes((short)type);
     byte[] payload = objType.Concat(objData).ToArray();
     _reliableClient.SendMessage(payload, payload.Length, QosType.Unreliable);
 }
 public static void SendMessageBroadcast(byte[] message, QosType qos)
 {
     foreach (var endpoint in endpointsByClient)
     {
         endpoint.Value.SendMessage(message, message.Length, qos);
     }
 }
        public static void Send(int hostId, int connectionId, Packet msg, QosType channel = NetworkConfig.DefaultChannel)
        {
            if (hostId < 0 || connectionId < 0)
            {
                return;
            }
            if (!IsOnline)
            {
                return;
            }

            try
            {
                byte error;
                NetworkTransport.Send(hostId, connectionId, NetworkConfig.Channels[channel], msg.Buffer, msg.Size, out error);
                if ((NetworkError)error != NetworkError.Ok)
                {
                    Debug.LogWarning(string.Format("Failed to send. : {0}", (NetworkError)error));
                }
            }
            catch (Exception error)
            {
                Debug.LogError(error);
            }
        }
 public NetBroadcastChannelMessage() : base()
 {
     NetId    = -1;
     NetType  = 0;
     ExceptId = -1;
     QoS      = QosType.AllCostDelivery;
 }
Beispiel #7
0
    private void SendJSONMessageToMaster(string JSONobject, QosType type)
    {
        byte error = 0;

        byte[] messageBuffer = Encoding.UTF8.GetBytes(JSONobject);
        //Debug.Log("Sending message of length " + messageBuffer.Length);

        if (type == QosType.Reliable)
        {
            Debug.Log("Sending reliable message.");
            NetworkTransport.Send(MS_socketID, MS_connectionID, TCP_ChannelID, messageBuffer, messageBuffer.Length, out error);
        }
        else if (type == QosType.Unreliable)
        {
            NetworkTransport.Send(MS_socketID, MS_connectionID, UDP_ChannelID, messageBuffer, messageBuffer.Length, out error);
        }
        else if (type == QosType.UnreliableFragmented)
        {
            NetworkTransport.Send(MS_socketID, MS_connectionID, UDP_ChannelIDFrag, messageBuffer, messageBuffer.Length, out error);
        }
        else if (type == QosType.UnreliableSequenced)
        {
            NetworkTransport.Send(MS_socketID, MS_connectionID, UDP_ChannelIDSeq, messageBuffer, messageBuffer.Length, out error);
        }
    }
Beispiel #8
0
        /// <summary>
        /// Sends the specified <see cref="DataMessage"/> to the server.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        protected bool Send(DataMessage message, QosType channel, out NetworkError error)
        {
            //Debug.Log(this.ToString() + " Sending message of type: " + message.type.ToString() + " on channel: " + type.ToString());
            var buffer = message.Serialize();

            return(base.Send(_localConnectionId, buffer, channel, message.GetTotalByteSize(), out error));
        }
Beispiel #9
0
        public void SendMessage(NetMessage netMsg, QosType qos, int netIdAddress, int exceptIdAddress = -1)
        {
            Debug.Log("Send Message: " + netMsg.Type);

            var buffer    = new byte[BUFFER_LENGTH];
            var formatter = new BinaryFormatter();
            var stream    = new MemoryStream(buffer);

            formatter.Serialize(stream, netMsg);

            if (netIdAddress == -1)
            {
                foreach (var connectionId in connections)
                {
                    if ((exceptIdAddress != -1 && connectionId != ConnectionIdByNetId[exceptIdAddress]) ||
                        (exceptIdAddress == -1))
                    {
                        NetworkTransport.Send(_hostId, connectionId, _QoSChannels[qos],
                                              buffer, BUFFER_LENGTH, out _error);
                    }
                }
            }
            else
            {
                NetworkTransport.Send(_hostId, ConnectionIdByNetId[netIdAddress], _QoSChannels[qos],
                                      buffer, BUFFER_LENGTH, out _error);
            }
        }
Beispiel #10
0
        public DataChannel(
            short channelID,
            QosType qos,
            Compression compression,
            Encryption encryption,
            ReceivedHandler onReceived,
            CheckMode checkMode = CheckMode.Sequre
            )
        {
            ChannelID   = channelID;
            Qos         = qos;
            Compression = compression;
            Encryption  = encryption;

            OnReceived += onReceived;

            CheckMode = checkMode;

            converter = DataSerializer.GetConverter(typeof(T));

            if (Compression == Compression.LZ4)
            {
                byteArrayConverter = DataSerializer.GetConverter(typeof(byte[]));
            }

            if (Encryption == Encryption.Rsa || Encryption == Encryption.Aes)
            {
                encArrayConverter = DataSerializer.GetConverter(typeof(byte[]));
            }
        }
Beispiel #11
0
 internal Writer(NetworkWriter writer, short messageIndex, NetworkConnection target, QosType qos)
 {
     _netWriter = writer;
     _target    = target;
     _qos       = qos;
     writer.StartMessage(messageIndex);
 }
Beispiel #12
0
    public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
    {
        if (steamId.m_SteamID == SteamUser.GetSteamID().m_SteamID)
        {
            // sending to self. short circuit
            TransportReceive(bytes, numBytes, channelId);
            error = 0;
            return(true);
        }

        EP2PSend eP2PSendType = EP2PSend.k_EP2PSendReliable;

        QosType qos = SteamNetworkManager.hostTopology.DefaultConfig.Channels[channelId].QOS;

        if (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced)
        {
            eP2PSendType = EP2PSend.k_EP2PSendUnreliable;
        }

        // Send packet to peer through Steam
        if (SteamNetworking.SendP2PPacket(steamId, bytes, (uint)numBytes, eP2PSendType, channelId))
        {
            error = 0;
            return(true);
        }
        else
        {
            error = 1;
            return(false);
        }
    }
        protected override void Initialize()
        {
            if ((int)this.UnreliableChannel >= NetworkManager.singleton.channels.Count)
            {
                throw this.Log.CreateUserErrorException("configured 'unreliable' channel is out of range", "set the wrong channel number in the HLAPI Comms Network component", "https://dissonance.readthedocs.io/en/latest/Basics/Quick-Start-UNet-HLAPI/", "B19B4916-8709-490B-8152-A646CCAD788E");
            }
            QosType qosType = NetworkManager.singleton.channels[(int)this.UnreliableChannel];

            if (qosType != QosType.Unreliable)
            {
                throw this.Log.CreateUserErrorException(string.Format("configured 'unreliable' channel has QoS type '{0}'", qosType), "not creating the channel with the correct QoS type", "https://dissonance.readthedocs.io/en/latest/Basics/Quick-Start-UNet-HLAPI/", "24ee53b1-7517-4672-8a4a-64a3e3c87ef6");
            }
            if ((int)this.ReliableSequencedChannel >= NetworkManager.singleton.channels.Count)
            {
                throw this.Log.CreateUserErrorException("configured 'reliable' channel is out of range", "set the wrong channel number in the HLAPI Comms Network component", "https://dissonance.readthedocs.io/en/latest/Basics/Quick-Start-UNet-HLAPI/", "5F5F2875-ECC8-433D-B0CB-97C151B8094D");
            }
            QosType qosType2 = NetworkManager.singleton.channels[(int)this.ReliableSequencedChannel];

            if (qosType2 != QosType.ReliableSequenced)
            {
                throw this.Log.CreateUserErrorException(string.Format("configured 'reliable sequenced' channel has QoS type '{0}'", qosType2), "not creating the channel with the correct QoS type", "https://dissonance.readthedocs.io/en/latest/Basics/Quick-Start-UNet-HLAPI/", "035773ec-aef3-477a-8eeb-c234d416171c");
            }
            short typeCode = this.TypeCode;

            if (HlapiCommsNetwork.< > f__mg$cache0 == null)
            {
                HlapiCommsNetwork.< > f__mg$cache0 = new NetworkMessageDelegate(HlapiCommsNetwork.NullMessageReceivedHandler);
            }
            NetworkServer.RegisterHandler(typeCode, HlapiCommsNetwork.< > f__mg$cache0);
            base.Initialize();
        }
Beispiel #14
0
    public int GetChannel(QosType QOSChannel)
    {
        int ChannelID;

        switch (QOSChannel)
        {
        case QosType.Reliable:
            ChannelID = ReliableChannelId;
            break;

        case QosType.ReliableSequenced:
            ChannelID = ReliableSequencedChannelId;
            break;

        case QosType.Unreliable:
            ChannelID = UnreliableChannelId;
            break;

        default:
            Debug.Log("QOS TYPE " + QOSChannel + " has not been implemented defaulting to Unreliable");
            ChannelID = UnreliableChannelId;
            break;
        }
        return(ChannelID);
    }
Beispiel #15
0
        /// <summary>
        /// Player1人にパケットを送信
        /// </summary>
        public override ushort Send(ushort targetPlayerId, DataStreamWriter data, QosType qos, bool noChunk = false)
        {
            if (state == State.Offline)
            {
                Debug.LogError("Send Failed : State.Offline");
                return(0);
            }
            ushort seqNum = 0;

            using (var writer = CreateSendPacket(data, qos, targetPlayerId, playerId)) {
                if (networkLinkerHandle.IsCreated)
                {
                    NetworkLinker linker = NetworkLinkerPool.GetLinker(networkLinkerHandle);
                    if (linker != null)
                    {
                        seqNum = linker.Send(writer, qos, noChunk);
                    }
                }
                else
                {
                    Debug.LogError("Send Failed : is not create networkLinker");
                }
            }
            return(seqNum);
        }
Beispiel #16
0
        public void SendRPC(RMPNetworkView sender, QosType channel, string methodName, params object[] parameters)
        {
            if (string.IsNullOrEmpty(sender.Guid))
            {
                Debug.LogWarning("RPC Aborted : The Guid is empty.");
                return;
            }

            if (parameters == null)
            {
                Debug.LogWarning("RPC Aborted : Parameters array can not be null.");
                return;
            }

            var msg = new Packet();

            msg.Push((byte)RMPEncoding.ProtocolId.RPC);
            msg.Push(sender.Guid);
            msg.Push(methodName);
            msg.Push(parameters.Length);

            foreach (object param in parameters)
            {
                RMPEncoding.PushParameter(msg, param);
            }

            NetworkService.Send(HostId, ConnectionId, msg);
        }
        // Token: 0x060020F4 RID: 8436 RVA: 0x0008E530 File Offset: 0x0008C730
        public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
        {
            if (this.ignore)
            {
                error = 0;
                return(true);
            }
            this.logNetworkMessages = SteamNetworkConnection.cvNetP2PLogMessages.value;
            Client instance = Client.Instance;

            if (this.steamId.value == instance.SteamId)
            {
                this.TransportReceive(bytes, numBytes, channelId);
                error = 0;
                if (SteamNetworkConnection.cvNetP2PDebugTransport.value)
                {
                    Debug.LogFormat("SteamNetworkConnection.TransportSend steamId=self numBytes={1} channelId={2}", new object[]
                    {
                        numBytes,
                        channelId
                    });
                }
                return(true);
            }
            Networking.SendType eP2PSendType = Networking.SendType.Reliable;
            QosType             qos          = GameNetworkManager.singleton.connectionConfig.Channels[channelId].QOS;

            if (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced)
            {
                eP2PSendType = Networking.SendType.Unreliable;
            }
            if (instance.Networking.SendP2PPacket(this.steamId.value, bytes, numBytes, eP2PSendType, 0))
            {
                error = 0;
                if (SteamNetworkConnection.cvNetP2PDebugTransport.value)
                {
                    Debug.LogFormat("SteamNetworkConnection.TransportSend steamId={0} numBytes={1} channelId={2} error={3}", new object[]
                    {
                        this.steamId.value,
                        numBytes,
                        channelId,
                        error
                    });
                }
                return(true);
            }
            error = 1;
            if (SteamNetworkConnection.cvNetP2PDebugTransport.value)
            {
                Debug.LogFormat("SteamNetworkConnection.TransportSend steamId={0} numBytes={1} channelId={2} error={3}", new object[]
                {
                    this.steamId.value,
                    numBytes,
                    channelId,
                    error
                });
            }
            return(false);
        }
Beispiel #18
0
 public static void Send(ushort playerId, DataStreamWriter data, QosType qos, bool noChunk = false)
 {
     if (NetworkManager == null || NetworkManager.state == State.Offline)
     {
         return;
     }
     NetworkManager.Send(playerId, data, qos, noChunk);
 }
Beispiel #19
0
 public static void Brodcast(DataStreamWriter data, QosType qos, bool noChunk = false)
 {
     if (NetworkManager == null || NetworkManager.state == State.Offline)
     {
         return;
     }
     NetworkManager.Brodcast(data, qos, noChunk);
 }
 public void SendPacketToServer(NetworkPacket packet, QosType ChannelType)
 {
     if (ServerConnectionID != -1)
     {
         byte error;
         NetworkTransport.Send(socketId, ServerConnectionID, GetChannel(ChannelType), packet.GetBytes(), packet.GetTotalPacketSize(), out error);
     }
 }
        /// <summary>
        /// Sends the specified byte array buffer over <see cref="NetworkTransport"/> to the specified connection identifier, using the given <see cref="QosType"/> channel.
        /// </summary>
        /// <param name="connectionId">The connection identifier.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="type">The type.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        public bool Send(int connectionId, byte[] buffer, QosType type, int size, out NetworkError error)
        {
            byte e;
            var  result = NetworkTransport.Send(_socketId, connectionId, GetChannelID(type), buffer, size, out e);

            error = (NetworkError)e;
            return(result);
        }
Beispiel #22
0
 public ChannelQOS(ChannelQOS channel)
 {
     if (channel == null)
     {
         throw new NullReferenceException("channel is not defined");
     }
     this.m_Type = channel.m_Type;
 }
 static bool IsReliableQoS(QosType qos)
 {
     if (qos != QosType.Reliable && qos != QosType.ReliableFragmented && qos != QosType.ReliableSequenced)
     {
         return(qos == QosType.ReliableStateUpdate);
     }
     return(true);
 }
Beispiel #24
0
 public ChannelQOS(ChannelQOS channel)
 {
     if (channel == null)
     {
         throw new NullReferenceException("channel is not defined");
     }
     this.m_Type = channel.m_Type;
 }
 static bool IsSequencedQoS(QosType qos)
 {
     if (qos != QosType.ReliableSequenced)
     {
         return(qos == QosType.UnreliableSequenced);
     }
     return(true);
 }
Beispiel #26
0
 /// <summary>
 /// 全Playerにパケットを送信
 /// </summary>
 public override void Brodcast(DataStreamWriter data, QosType qos, bool noChunk = false)
 {
     if (state == State.Offline)
     {
         Debug.LogError("Send Failed : State.Offline");
         return;
     }
     Send(ushort.MaxValue, data, qos, noChunk);
 }
Beispiel #27
0
    public static void SendToServerOnly(NetworkPacket Packet, QosType QualityOfServiceType)
    {
        Packet.SetPacketTarget(PacketTargets.ServerOnly);
#if SERVER
        NetworkPacketReader.ReadPacket(Packet, NetworkDetails.GetLocalConnectionID(), true);
#else
        ClientNetworkManager.Instance.SendPacketToServer(Packet, QualityOfServiceType);
#endif
    }
Beispiel #28
0
 //Init:
 public void Reset()
 {
     broadcastingPort          = 47777;
     initialBandwidth          = 500000;
     showGUI                   = false;
     broadcastData             = "";
     primaryQualityOfService   = QosType.Reliable;
     secondaryQualityOfService = QosType.Unreliable;
 }
Beispiel #29
0
 public void Reset()
 {
     maxConnections            = 1;
     showGUI                   = false;
     broadcastingPort          = 47777;
     initialBandwidth          = 500000;
     primaryQualityOfService   = QosType.UnreliableSequenced;
     secondaryQualityOfService = QosType.Reliable;
 }
Beispiel #30
0
 public ChannelQOS(ChannelQOS channel)
 {
     if (channel == null)
     {
         throw new NullReferenceException("channel is not defined");
     }
     m_Type = channel.m_Type;
     m_BelongsSharedOrderChannel = channel.m_BelongsSharedOrderChannel;
 }
        public void Send <T>(RemoteClient client, T data, MessageType type, QosType qosType = QosType.Unreliable)
        {
            var objData = StructTools.RawSerialize(data);
            var objType = BitConverter.GetBytes((short)type);
            var payload = objType.Concat(objData).ToArray();

            _clients.TryGetValue(client, out var reliableEndpoint);
            reliableEndpoint?.SendMessage(payload, payload.Length, qosType);
        }
 protected void RpcClients(byte methodId, QosType qosType, params System.Object[] args)
 {
     backstab.RpcAll(viewId, methodId, qosType, args);
 }
 /// <summary>
 ///   <para></para>
 /// </summary>
 /// <param name="value">Add new channel to configuration.</param>
 /// <returns>
 ///   <para>Channel id, user can use this id to send message via this channel.</para>
 /// </returns>
 public byte AddChannel(QosType value)
 {
   if (this.m_Channels.Count > (int) byte.MaxValue)
     throw new ArgumentOutOfRangeException("Channels Count should be less than 256");
   if (!Enum.IsDefined(typeof (QosType), (object) value))
     throw new ArgumentOutOfRangeException("requested qos type doesn't exist: " + (object) value);
   this.m_Channels.Add(new ChannelQOS(value));
   return (byte) (this.m_Channels.Count - 1);
 }
Beispiel #34
0
 public ChannelData(QosType qosType, int id)
 {
     this.qosType = qosType;
     this.id = id;
 }
Beispiel #35
0
 public void Rpc(int viewId, byte methodId, QosType qtype, int connectionId, System.Object[] args)
 {
     Rpc(viewId, methodId, GetChannel(qtype), connectionId, args);
 }
Beispiel #36
0
 private int GetChannel(QosType qtype)
 {
     for (int i = 0; i < channelData.Length; i++) {
         if (channelData[i].qosType == qtype) {
             return channelData[i].id;
         }
     }
     return -1;
 }
 private static bool IsSequencedQoS(QosType qos)
 {
     return ((qos == QosType.ReliableSequenced) || (qos == QosType.UnreliableSequenced));
 }
 private static bool IsReliableQoS(QosType qos)
 {
     return ((((qos == QosType.Reliable) || (qos == QosType.ReliableFragmented)) || (qos == QosType.ReliableSequenced)) || (qos == QosType.ReliableStateUpdate));
 }
 /// <summary>
 /// 
 /// <para/>
 /// 
 /// </summary>
 /// <param name="value">Add new channel to configuration.</param>
 /// <returns>
 /// 
 /// <para>
 /// Channel id, user can use this id to send message via this channel.
 /// </para>
 /// 
 /// </returns>
 public byte AddChannel(QosType value)
 {
     if (this.m_Channels.Count > (int) byte.MaxValue)
     throw new ArgumentOutOfRangeException("Channels Count should be less than 256");
       this.m_Channels.Add(new ChannelQOS(value));
       return (byte) (this.m_Channels.Count - 1);
 }
 private static bool IsReliableQoS(QosType qos)
 {
   if (qos != QosType.Reliable && qos != QosType.ReliableFragmented && qos != QosType.ReliableSequenced)
     return qos == QosType.ReliableStateUpdate;
   return true;
 }
 public extern byte AddChannel(QosType value);
 public byte AddChannel(QosType value);
Beispiel #43
0
 public ChannelQOS()
 {
     this.m_Type = QosType.Unreliable;
 }
Beispiel #44
0
 public byte AddChannel(QosType value)
 {
     if (this.m_Channels.Count > 0xff)
     {
         throw new ArgumentOutOfRangeException("Channels Count should be less than 256");
     }
     if (!Enum.IsDefined(typeof(QosType), value))
     {
         throw new ArgumentOutOfRangeException("requested qos type doesn't exist: " + ((int) value));
     }
     ChannelQOS item = new ChannelQOS(value);
     this.m_Channels.Add(item);
     return (byte) (this.m_Channels.Count - 1);
 }
Beispiel #45
0
 public ChannelQOS(QosType value)
 {
     this.m_Type = value;
 }
 public RpcAttribute(QosType qosType)
 {
     this.qosType = qosType;
 }
Beispiel #47
0
 //Sending
 public void RpcAll(int viewId, byte methodId, QosType qtype, object[] args)
 {
     RpcAll(viewId, methodId, GetChannel(qtype), args);
 }
 protected void RpcServer(byte methodId, QosType qosType, params System.Object[] args)
 {
     if (backstab.IsServer) {
         Debug.LogError("Can't send to server if already server.");
         return;
     }
     backstab.Rpc(viewId, methodId, qosType, 1, args);
 }