Example #1
0
        /* Variables */

        /* Setter & Getter */

        /* Functions */

        /// <summary>
        /// Initialize the whole application. (In Unity layer.)
        /// </summary>
        /// <returns></returns>
        public static bool InitializeApplication()
        {
            if (!JCS_NetworkSettings.instance.ONLINE_MODE)
            {
                return(false);
            }

            JCS_Debug.Log("Online Mode is enabled");

            // Create Connection
            if (!JCS_NetworkSettings.CreateNetwork(
                    JCS_NetworkSettings.instance.HOST_NAME,
                    JCS_NetworkSettings.instance.PORT,
                    JCS_NetworkSettings.GetPresetClientHandler()))
            {
                // Faild handle
                return(false);
            }

            // Create keys
            JCS_NetworkManager.CreateKey();

            // 這裡無法判別
            return(true);
        }
        private void Test()
        {
            if (JCS_Input.GetKeyDown(KeyCode.P))
            {
                byte[] bytesSend = new byte[5];
                bytesSend[0] = (byte)'H';
                bytesSend[1] = (byte)'E';
                bytesSend[2] = (byte)'l';
                bytesSend[3] = (byte)'L';
                bytesSend[4] = (byte)'o';
                JCS_NetworkSettings.GetGameSocket().SendPacket(bytesSend);
            }

            if (JCS_Input.GetKeyDown(KeyCode.O))
            {
                byte[] bytesSend = new byte[10];
                bytesSend[0] = (byte)'Z';
                bytesSend[1] = (byte)'X';
                bytesSend[2] = (byte)'C';
                bytesSend[3] = (byte)'V';
                bytesSend[4] = (byte)'B';
                bytesSend[5] = (byte)'N';
                bytesSend[6] = (byte)'M';
                bytesSend[7] = (byte)',';
                bytesSend[8] = (byte)'.';
                bytesSend[9] = (byte)'/';
                JCS_NetworkSettings.GetGameSocket().SendPacket(bytesSend);
            }
        }
Example #3
0
        //----------------------
        // Private Functions

        /// <summary>
        /// Track each packet, if need to resend packet. Send it.
        /// </summary>
        private void TrackPacket()
        {
            if (JCS_NetworkSettings.GetGameSocket() != null &&
                !JCS_NetworkSettings.GetGameSocket().IsConnected())
            {
                return;
            }

            mResendTimer += Time.deltaTime;

            if (mResendTimer < mResendTime)
            {
                return;
            }

            // reset timer.
            mResendTimer = 0;


            /* First check if the packet responded? Remove it if
             * already responded. */
            {
                for (int index = 0;
                     index < mWaitingPacketIds.Count;
                     ++index)
                {
                    JCS_Packet packet   = mWaitingPackets[index];
                    short      packetId = mWaitingPacketIds[index];

                    if (mRespondPacketIds.Contains(packetId))
                    {
                        // responded, so remove it.
                        mWaitingPacketIds.Remove(packetId);
                        mWaitingPackets.Remove(packet);
                    }
                }
            }

            // cleanup the respond packet id.
            mRespondPacketIds.Clear();

            /* Resend the packet if necessary. */
            for (int index = 0;
                 index < mWaitingPackets.Count;
                 ++index)
            {
                JCS_Packet packet = mWaitingPackets[index];

                // re-send the packet
                JCS_NetworkSettings.GetGameSocket().SendPacket(packet.GetBytes());
            }
        }