예제 #1
0
        public PacketProtocol(NetworkStream stream, PacketQueue packetQueue)
        {
            this.stream      = stream;
            this.packetQueue = packetQueue;

            writer = new BinaryWriter(stream);
            reader = new BinaryReader(stream);
        }
예제 #2
0
        public Client(string host, int port, PacketQueue packetQueue)
        {
            this.host        = host;
            this.port        = port;
            this.packetQueue = packetQueue;

            Thread thread = new Thread(RunMain);

            thread.Name         = "Server Connection";
            thread.IsBackground = true;
            thread.Start();
        }
예제 #3
0
        /// <summary>
        /// Initialize component, or destroy if an active instance of it already
        /// exists.
        /// </summary>
        void Awake()
        {
            if (net != null)
            {
                Destroy(this);
                return;
            }

            net = this;
            DontDestroyOnLoad(net);

            packetExecutor = GetComponent <IPacketExecutorContext>();

            packetQueue = new PacketQueue();
            client      = new Client("localhost", port, packetQueue);
        }
예제 #4
0
        public void Stop()
        {
            if (!IsRunning)
            {
                return;
            }

            lock (tcp)
            {
                Debug.Log("Stopping client...");
                stream.Close();
                tcp.Close();

                // Drop all memory
                tcp            = null;
                stream         = null;
                packetQueue    = null;
                packetProtocol = null;
            }
        }