Send() public static method

public static Send ( int hostId, int connectionId, int channelId, byte buffer, int size, byte &error ) : bool
hostId int
connectionId int
channelId int
buffer byte
size int
error byte
return bool
Esempio n. 1
0
        public override void Send(ulong clientID, ArraySegment <byte> data, byte channel)
        {
            GetUnetConnectionDetails(clientID, out byte hostID, out ushort connectionID);

            byte[] buffer;

            if (data.Offset > 0)
            {
                // UNET cant handle this, do a copy

                if (messageBuffer.Length >= data.Count)
                {
                    buffer = messageBuffer;
                }
                else
                {
                    if (temporaryBufferReference != null && temporaryBufferReference.IsAlive && ((byte[])temporaryBufferReference.Target).Length >= data.Count)
                    {
                        buffer = (byte[])temporaryBufferReference.Target;
                    }
                    else
                    {
                        buffer = new byte[data.Count];
                        temporaryBufferReference = new WeakReference(buffer);
                    }
                }

                Buffer.BlockCopy(data.Array, data.Offset, buffer, 0, data.Count);
            }
            else
            {
                buffer = data.Array;
            }

            /*RelayTransport.*/
            Unet.Send(hostID, connectionID, m_UnetChannelLookup[channel], buffer, data.Count, out byte error);
        }
Esempio n. 2
0
 public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
 {
     return(NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error));
 }
 public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error) =>
 NetworkTransport.Send(this.hostId, this.connectionId, channelId, bytes, numBytes, out error);
 public bool Send(int hostId, int connectionId, int channelId, byte[] buffer, int size, out byte error)
 {
     return(NetworkTransport.Send(hostId, connectionId, channelId, buffer, size, out error));
 }
Esempio n. 5
0
        private static NetworkEventType BaseReceive(NetworkEventType @event, int hostId, ref int connectionId, ref int channelId, byte[] buffer, int bufferSize, ref int receivedSize, ref byte error)
        {
            switch (@event)
            {
            case NetworkEventType.DataEvent:
                MessageType messageType = (MessageType)buffer[0];
                switch (messageType)
                {
                case MessageType.ConnectToServer:         // Connection approved
                {
                    if (!isClient)
                    {
                        connectionId = (ushort)(buffer[1] | (buffer[2] << 8));             // Parse connection id
                    }
                    return(NetworkEventType.ConnectEvent);
                }

                case MessageType.Data:
                {
                    if (isClient)
                    {
                        // Remove our headers
                        ReverseOffset(buffer, 1, receivedSize);
                        --receivedSize;
                    }
                    else
                    {
                        // Remove our headers
                        connectionId = buffer.FromBytes(1);
                        ReverseOffset(buffer, 3, receivedSize);
                        receivedSize -= 3;
                    }
                    return(NetworkEventType.DataEvent);
                }

                case MessageType.ClientDisconnect:
                {
                    connectionId = (ushort)(buffer[1] | (buffer[2] << 8));             // Parse connection id
                    return(NetworkEventType.DisconnectEvent);
                }
                }
                break;

            case NetworkEventType.ConnectEvent:
            {
                if (isClient)
                {
                    //Connect via relay
                    string s = new StringBuilder(address).Append(':').Append(port).ToString();
                    buffer[0] = (byte)MessageType.ConnectToServer;
                    buffer[1] = (byte)s.Length;
                    for (int i = 0; i < s.Length; i++)
                    {
                        buffer[i + 2] = (byte)s[i];         // Get ASCII characters
                    }

                    NetworkTransport.Send(hostId, connectionId, GetReliableChannel(), buffer, s.Length + 2, out error);
                }
                else
                {
                    //Register us as a server
                    buffer[0] = (byte)MessageType.StartServer;
                    NetworkTransport.Send(hostId, connectionId, GetReliableChannel(), buffer, 1, out error);
                }
                return(NetworkEventType.Nothing);        // Connect event is ignored
            }

            case NetworkEventType.DisconnectEvent:
            {
                if ((NetworkError)error == NetworkError.CRCMismatch)
                {
                    Debug.LogError("[MLAPI.Relay] The MLAPI Relay detected a CRC missmatch. This could be due to the maxClients or other connectionConfig settings not being the same");
                }
                return(NetworkEventType.DisconnectEvent);
            }
            }
            return(@event);
        }