Exemplo n.º 1
0
        /// <summary>
        /// Close the connection.
        /// </summary>

        public void Close(bool notify)
        {
            stage = Stage.NotConnected;
            name  = "Guest";
            data  = null;

            if (mReceiveBuffer != null)
            {
                mReceiveBuffer.Recycle();
                mReceiveBuffer = null;
            }

            if (mSocket != null)
            {
                try
                {
                    if (mSocket.Connected)
                    {
                        mSocket.Shutdown(SocketShutdown.Both);
                    }
                    mSocket.Close();
                }
                catch (System.Exception) {}
                mSocket = null;

                if (notify)
                {
                    Buffer buffer = Buffer.Create();
                    buffer.BeginPacket(Packet.Disconnect);
                    buffer.EndTcpPacketWithOffset(4);
                    lock (mIn) mIn.Enqueue(buffer);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add an error packet to the incoming queue.
        /// </summary>

        void RespondWithError(Buffer buffer, string error)
        {
#if UNITY_EDITOR
            Debug.LogError(error);
#endif
            buffer.BeginPacket(Packet.Error).Write(error);
            buffer.EndTcpPacketWithOffset(4);
            lock (mIn) mIn.Enqueue(buffer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Close the connection.
        /// </summary>

        void CloseNotThreadSafe(bool notify)
        {
            Buffer.Recycle(mOut);
            stage = Stage.NotConnected;

            if (mSocket != null)
            {
                try
                {
                    if (mSocket.Connected)
                    {
                        mSocket.Shutdown(SocketShutdown.Both);
                    }
                    mSocket.Close();
                }
                catch (System.Exception) {}
                mSocket = null;

                if (notify)
                {
                    Buffer buffer = Buffer.Create();
                    buffer.BeginPacket(Packet.Disconnect);
                    buffer.EndTcpPacketWithOffset(4);

                    lock (mIn)
                    {
                        Buffer.Recycle(mIn);
                        mIn.Enqueue(buffer);
                    }
                }
                else
                {
                    lock (mIn) Buffer.Recycle(mIn);
                }
            }
            else if (notify && sendQueue != null)
            {
                sendQueue = null;
                Buffer buffer = Buffer.Create();
                buffer.BeginPacket(Packet.Disconnect);
                buffer.EndTcpPacketWithOffset(4);

                lock (mIn)
                {
                    Buffer.Recycle(mIn);
                    mIn.Enqueue(buffer);
                }
            }

            if (mReceiveBuffer != null)
            {
                mReceiveBuffer.Recycle();
                mReceiveBuffer = null;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add an error packet to the incoming queue.
        /// </summary>

        public void Error(IPEndPoint ip, string error)
        {
            Buffer buffer = Buffer.Create();

            buffer.BeginPacket(Packet.Error).Write(error);
            buffer.EndTcpPacketWithOffset(4);

            Datagram dg = new Datagram();

            dg.buffer = buffer;
            dg.ip     = ip;
            lock (mIn) mIn.Enqueue(dg);
        }
        /// <summary>
        /// Add an error packet to the incoming queue.
        /// </summary>

        public void Error(IPEndPoint ip, string error)
        {
#if UNITY_EDITOR
            UnityEngine.Debug.LogError(error);
#endif
            Buffer buffer = Buffer.Create();
            buffer.BeginPacket(Packet.Error).Write(error);
            buffer.EndTcpPacketWithOffset(4);

            Datagram dg = new Datagram();
            dg.buffer = buffer;
            dg.ip     = ip;
            lock (mIn) mIn.Enqueue(dg);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add an error packet to the incoming queue.
        /// </summary>

        void Error(Buffer buffer, string error)
        {
            buffer.BeginPacket(Packet.Error).Write(error);
            buffer.EndTcpPacketWithOffset(4);
            lock (mIn) mIn.Enqueue(buffer);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Close the connection.
        /// </summary>

        void CloseNotThreadSafe(bool notify)
        {
#if !MODDING
#if STANDALONE || UNITY_EDITOR
            if (id != 0)
            {
                Tools.Log(name + " (" + address + "): Disconnected [" + id + "]");
            }
#endif
            Buffer.Recycle(mOut);
            stage    = Stage.NotConnected;
            mSending = false;

            if (mSocket != null || custom != null)
            {
                if (mSocket != null)
                {
                    try
                    {
                        if (mSocket.Connected)
                        {
                            mSocket.Shutdown(SocketShutdown.Both);
                        }
                        mSocket.Close();
                    }
                    catch (System.Exception) { }
                    mSocket = null;
                }

                if (custom != null)
                {
                    custom.OnDisconnect();
                }

                if (notify)
                {
                    var buffer = Buffer.Create();
                    buffer.BeginPacket(Packet.Disconnect);
                    buffer.EndTcpPacketWithOffset(4);

                    lock (mIn)
                    {
                        Buffer.Recycle(mIn);
                        mIn.Enqueue(buffer);
                    }
                }
                else
                {
                    lock (mIn) Buffer.Recycle(mIn);
                }
            }
            else if (notify && sendQueue != null)
            {
                sendQueue = null;
                Buffer buffer = Buffer.Create();
                buffer.BeginPacket(Packet.Disconnect);
                buffer.EndTcpPacketWithOffset(4);

                lock (mIn)
                {
                    Buffer.Recycle(mIn);
                    mIn.Enqueue(buffer);
                }
            }

            if (mReceiveBuffer != null)
            {
                mReceiveBuffer.Recycle();
                mReceiveBuffer = null;
            }

            if (onClose != null)
            {
                onClose(this);
            }

            id = 0;
#endif
        }
Exemplo n.º 8
0
 /// <summary>
 /// Add an error packet to the incoming queue.
 /// </summary>
 void Error(Buffer buffer, string error)
 {
     buffer.BeginPacket(Packet.Error).Write(error);
     buffer.EndTcpPacketWithOffset(4);
     lock (mIn) mIn.Enqueue(buffer);
 }