Ejemplo n.º 1
0
    public static void ThreadUpdate(System.Object obj)
    {
        Main mainobj = (Main)obj;

        StartListening();
        BattlePlayersInfo.instance.InitPlayerInfoTest();
        while (mainobj.isRunning)
        {
            // do send queue
            NetSend.SendLogic();
            // do receive msg queue
            NetReceive.ReceiveLogic();

            // sleep
            System.Threading.Thread.Sleep(100);
        }
        CloseListening();
    }
Ejemplo n.º 2
0
    private void ConnectCallback(IAsyncResult asyncConnect)
    {
        try
        {
            this._socket = (Socket)asyncConnect.AsyncState;

            this._net_send    = new NetSend(this._socket, this._send_queue);
            this._net_receive = new NetReceive(this._socket, this._receive_queue);

            this._socket.EndConnect(asyncConnect);

            EventMgr.Inst.SendEvent(EventDef.NetConnectSuccess);
        }
        catch (Exception e)
        {
            EventMgr.Inst.SendEvent(EventDef.NetConnectFaild);
            Debug.LogError("socket connect faild error: " + e);
        }
    }
Ejemplo n.º 3
0
    private void Closed()
    {
        lock (this._send_queue) { this._send_queue.Clear(); }
        lock (this._receive_queue) { this._receive_queue.Clear(); }

        if (this._socket != null && this._socket.Connected)
        {
            this._socket.Shutdown(SocketShutdown.Both);
            this._socket.Close();
        }
        this._socket = null;

        if (this._net_send != null)
        {
            this._net_send.AppQuit();
            this._net_send = null;
        }
        if (this._net_receive != null)
        {
            this._net_receive.AppQuit();
            this._net_receive = null;
        }
    }