예제 #1
0
    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;
        }
    }
예제 #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);
            }
        }
    }
예제 #3
0
 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);
 }
예제 #4
0
 public static void SendMessageBroadcast(byte[] message, QosType qos)
 {
     foreach (var endpoint in endpointsByClient)
     {
         endpoint.Value.SendMessage(message, message.Length, qos);
     }
 }
예제 #5
0
        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;
 }
예제 #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);
        }
    }
예제 #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));
        }
예제 #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);
            }
        }
예제 #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[]));
            }
        }
예제 #11
0
파일: Writer.cs 프로젝트: xiaoxiao921/R2API
 internal Writer(NetworkWriter writer, short messageIndex, NetworkConnection target, QosType qos)
 {
     _netWriter = writer;
     _target    = target;
     _qos       = qos;
     writer.StartMessage(messageIndex);
 }
예제 #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);
        }
    }
예제 #13
0
        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();
        }
예제 #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);
    }
예제 #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);
        }
예제 #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);
        }
예제 #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);
 }
예제 #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);
     }
 }
예제 #21
0
        /// <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);
        }
예제 #22
0
 public ChannelQOS(ChannelQOS channel)
 {
     if (channel == null)
     {
         throw new NullReferenceException("channel is not defined");
     }
     this.m_Type = channel.m_Type;
 }
예제 #23
0
 static bool IsReliableQoS(QosType qos)
 {
     if (qos != QosType.Reliable && qos != QosType.ReliableFragmented && qos != QosType.ReliableSequenced)
     {
         return(qos == QosType.ReliableStateUpdate);
     }
     return(true);
 }
예제 #24
0
 public ChannelQOS(ChannelQOS channel)
 {
     if (channel == null)
     {
         throw new NullReferenceException("channel is not defined");
     }
     this.m_Type = channel.m_Type;
 }
예제 #25
0
 static bool IsSequencedQoS(QosType qos)
 {
     if (qos != QosType.ReliableSequenced)
     {
         return(qos == QosType.UnreliableSequenced);
     }
     return(true);
 }
예제 #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);
 }
예제 #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
    }
예제 #28
0
파일: Client.cs 프로젝트: d4160/Surge
 //Init:
 public void Reset()
 {
     broadcastingPort          = 47777;
     initialBandwidth          = 500000;
     showGUI                   = false;
     broadcastData             = "";
     primaryQualityOfService   = QosType.Reliable;
     secondaryQualityOfService = QosType.Unreliable;
 }
예제 #29
0
 public void Reset()
 {
     maxConnections            = 1;
     showGUI                   = false;
     broadcastingPort          = 47777;
     initialBandwidth          = 500000;
     primaryQualityOfService   = QosType.UnreliableSequenced;
     secondaryQualityOfService = QosType.Reliable;
 }
예제 #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;
 }
예제 #31
0
        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);
        }
예제 #32
0
 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);
 }
예제 #34
0
 public ChannelData(QosType qosType, int id)
 {
     this.qosType = qosType;
     this.id = id;
 }
예제 #35
0
 public void Rpc(int viewId, byte methodId, QosType qtype, int connectionId, System.Object[] args)
 {
     Rpc(viewId, methodId, GetChannel(qtype), connectionId, args);
 }
예제 #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;
 }
예제 #37
0
 private static bool IsSequencedQoS(QosType qos)
 {
     return ((qos == QosType.ReliableSequenced) || (qos == QosType.UnreliableSequenced));
 }
예제 #38
0
 private static bool IsReliableQoS(QosType qos)
 {
     return ((((qos == QosType.Reliable) || (qos == QosType.ReliableFragmented)) || (qos == QosType.ReliableSequenced)) || (qos == QosType.ReliableStateUpdate));
 }
예제 #39
0
 /// <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);
예제 #43
0
 public ChannelQOS()
 {
     this.m_Type = QosType.Unreliable;
 }
예제 #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);
 }
예제 #45
0
 public ChannelQOS(QosType value)
 {
     this.m_Type = value;
 }
예제 #46
0
 public RpcAttribute(QosType qosType)
 {
     this.qosType = qosType;
 }
예제 #47
0
 //Sending
 public void RpcAll(int viewId, byte methodId, QosType qtype, object[] args)
 {
     RpcAll(viewId, methodId, GetChannel(qtype), args);
 }
예제 #48
0
 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);
 }