Esempio n. 1
0
    private void OnApplicationQuit()
    {
        if (_server != null)
        {
            DefinedStructure.P_Request pConnectionTerminate;

            ToPacket(DefinedProtocol.eFromClient.ConnectionTerminate, pConnectionTerminate);

            DefinedStructure.PacketInfo packetRecieve;
            packetRecieve._id   = (int)DefinedProtocol.eFromClient.ConnectionTerminate;
            packetRecieve._data = new byte[1024];
            byte[] temp = ConvertPacket.StructureToByteArray(pConnectionTerminate);
            for (int n = 0; n < temp.Length; n++)
            {
                packetRecieve._data[n] = temp[n];
            }
            packetRecieve._totalSize = temp.Length;

            _server.Send(ConvertPacket.StructureToByteArray(packetRecieve));

            try
            {
                _server.Shutdown(SocketShutdown.Both);
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
            }
            finally
            {
                _server.Close(0);
                _server = null;
            }
        }
    }
Esempio n. 2
0
    void ToPacket(DefinedProtocol.eFromClient fromClientID, object str)
    {
        DefinedStructure.PacketInfo packetRecieve;
        packetRecieve._id   = (int)fromClientID;
        packetRecieve._data = new byte[1024];
        byte[] temp = ConvertPacket.StructureToByteArray(str);
        for (int n = 0; n < temp.Length; n++)
        {
            packetRecieve._data[n] = temp[n];
        }
        packetRecieve._totalSize = temp.Length;

        _fromClientQueue.Enqueue(ConvertPacket.StructureToByteArray(packetRecieve));
    }