Example #1
0
        public static void ResetNetworkSystem()
        {
            NetworkConnection.ResetRequested = true;

            ClientConnection = new NetClient(Config);
            ClientConnection.Start();

            NetworkServerList.RefreshMasterServers();

            if (SendThread != null && !SendThread.IsCompleted)
            {
                SendThread?.Wait(1000);
            }
            if (ReceiveThread != null && !ReceiveThread.IsCompleted)
            {
                ReceiveThread?.Wait(1000);
            }

            NetworkConnection.ResetRequested = false;

            ReceiveThread = SystemBase.LongRunTaskFactory.StartNew(NetworkReceiver.ReceiveMain);
            SendThread    = SystemBase.LongRunTaskFactory.StartNew(NetworkSender.SendMain);

            NetworkServerList.RequestServers();
        }
Example #2
0
        public static void ResetNetworkSystem()
        {
            NetworkConnection.ResetRequested    = true;
            BannedPartsWindow.Singleton.Display = false;

            if (ClientConnection?.Status > NetPeerStatus.NotRunning)
            {
                ClientConnection.Shutdown("Disconnected");
                Thread.Sleep(1000);
            }

            //This will set the NetPeerConfiguration locked as FALSE and allow to change MTU and other advanced stuff
            Config = Config.Clone();

            ClientConnection = new NetClient(Config);

            if (SendThread != null && !SendThread.IsCompleted)
            {
                SendThread.Wait(1000);
            }
            if (ReceiveThread != null && !ReceiveThread.IsCompleted)
            {
                ReceiveThread.Wait(1000);
            }

            NetworkConnection.ResetRequested = false;

            ReceiveThread = SystemBase.LongRunTaskFactory.StartNew(NetworkReceiver.ReceiveMain);
            SendThread    = SystemBase.LongRunTaskFactory.StartNew(NetworkSender.SendMain);
        }
Example #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed || disposing)
            {
                try
                {
                    sock.Shutdown(SocketShutdown.Both);
                    sock.Close();

                    for (int i = 0; i < SocketAsynPool.Count; i++)
                    {
                        SocketAsyncEventArgs args = SocketAsynPool.Pop();

                        BuffManagers.FreeBuffer(args);
                    }


                    ReceiveThread.Abort();
                }
                catch
                {
                }

                isDisposed = true;
            }
        }
        public static void ResetNetworkSystem()
        {
            NetworkConnection.ResetRequested             = true;
            BannedPartsResourcesWindow.Singleton.Display = false;

            if (ClientConnection.Status > NetPeerStatus.NotRunning)
            {
                ClientConnection.Shutdown("Disconnected");
                Thread.Sleep(1000);
            }

            if (SendThread != null && !SendThread.IsCompleted)
            {
                SendThread.Wait(1000);
            }
            if (ReceiveThread != null && !ReceiveThread.IsCompleted)
            {
                ReceiveThread.Wait(1000);
            }

            NetworkConnection.ResetRequested = false;

            ReceiveThread = SystemBase.LongRunTaskFactory.StartNew(NetworkReceiver.ReceiveMain);
            SendThread    = SystemBase.LongRunTaskFactory.StartNew(NetworkSender.SendMain);
        }
Example #5
0
 public static void UnInit()
 {
     ReceiveThread.Abort();
     ReceiveThread = null;
     Client.Close();
     Client = null;
 }
Example #6
0
        public static void ResetNetworkSystem()
        {
            NetworkConnection.ResetRequested = true;

            if (ClientConnection?.Status > NetPeerStatus.NotRunning)
            {
                ClientConnection.Shutdown("Disconnected");
                Thread.Sleep(1000);
            }

            ClientConnection = new NetClient(Config);
            ClientConnection.Start();

            if (SendThread != null && !SendThread.IsCompleted)
            {
                SendThread.Wait(1000);
            }
            if (ReceiveThread != null && !ReceiveThread.IsCompleted)
            {
                ReceiveThread.Wait(1000);
            }

            NetworkConnection.ResetRequested = false;

            ReceiveThread = SystemBase.LongRunTaskFactory.StartNew(NetworkReceiver.ReceiveMain);
            SendThread    = SystemBase.LongRunTaskFactory.StartNew(NetworkSender.SendMain);
        }
Example #7
0
 public static void UnInit()
 {
     ReceiveThread.Abort();
     ReceiveThread = null;
     Server.Dispose();
     Server.Close();
     Server = null;
 }
Example #8
0
        public static void StartNetworkSystem()
        {
            Config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
            Config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
            Config.EnableMessageType(NetIncomingMessageType.UnconnectedData);

            ClientConnection = new NetClient(Config);
            ClientConnection.Start();

            NetworkServerList.RefreshMasterServers();
            SendThread.Start(TaskScheduler.Default);
            ReceiveThread.Start(TaskScheduler.Default);
            NetworkServerList.RequestServers();
        }
 public bool StopExchange()
 {
     m_bRun = false;
     _device.CloseCan();
     try
     {
         if ((ReceiveThread.ThreadState & (ThreadState.Stopped | ThreadState.Unstarted)) == 0)
         {
             ReceiveThread.Abort();
             ReceiveThread.Join(); //Thread stops
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Example #10
0
 /// <summary>
 /// Suspends the listening for incoming PDU's.
 /// </summary>
 public void StopListening()
 {
     FlushBuffer();
     ReceiveThread.Abort();
 }
Example #11
0
 /// <summary>
 /// Starts the background thread that listens for incoming PDU's.
 /// </summary>
 public void StartListening()
 {
     ThreadSetup();
     ReceiveThread.Start();
 }
Example #12
0
        private void ListenClientConnect()
        {
            while (true)
            {
                if (_serverReady && _serverSocket != null)
                {
                    Socket clientSocket = _serverSocket.Accept();
                    clientSocket.IOControl(IOControlCode.KeepAliveValues, GetKeepOption(), null);
                    string ip = clientSocket.RemoteEndPoint.ToString();
                    MBConnect c = new MBConnect(clientSocket, ip);
                    _connections[ip] = c;
                    Log.InfoFormat("客户端已连接: {0} ", ip);
                    if (OnClientConnect != null)
                    {
                        OnClientConnect.Invoke(c);
                    }

                    ReceiveThread _client = new ReceiveThread(this, c);
                    _client.OnMsgDealed = _OnMsgDealed;
                    Thread t = new Thread(_client.DoWork);
                    t.Start();
                }
                else
                {
                    break;// 停止.
                }
                Thread.Sleep(10);
            }
        }
 public NetValueObject()
 {
     _thread = new ReceiveThread (this);
     values = new ValueGroupCtl ();
 }
 public NetValueObject()
 {
     _thread = new ReceiveThread(this);
     values  = new ValueGroupCtl();
 }
Example #15
0
    void Awake()
    {
        //create obj
        string redTag  = "";
        string blueTag = "";
        ST     pp      = ST.getInstance();

        //print (pp.P);
        if (pp.P == 1)
        {
            redTag  = "Player";
            blueTag = "P2";
        }
        else
        {
            redTag  = "P2";
            blueTag = "Player";
        }
        Red.parent   = GameObject.FindWithTag("Red").transform;
        Red.yasuo    = Resources.Load("Prefabs/taunt", typeof(GameObject));
        Red.HPPrefab = Resources.Load("Prefabs/HPCanvas", typeof(GameObject));
        GameObject yasuo = null;

        MakeObject(redTag, Red.rotate, Red.yasuodis, Red.parent, Red.yasuo, ref yasuo);
        Vector3 V1 = yasuo.transform.position; V1.z -= 10; yasuo.transform.position = V1;

        //yasuo.AddComponent<CharacterController> ();
        //yasuo.GetComponent<CharacterController> ().center = new Vector3(0,1,0);
        //yasuo.AddComponent<CC_test> ();
        //yasuo.AddComponent<Numeric> ();
        yasuo.GetComponent <Numeric>().tagString = redTag;


        Blue.parent = GameObject.FindWithTag("Blue").transform;
        Blue.yasuo  = Resources.Load("Prefabs/taunt", typeof(GameObject));
        GameObject yasuo2 = null;

        MakeObject(blueTag, Blue.rotate, Blue.yasuodis, Blue.parent, Blue.yasuo, ref yasuo2);
        Vector3 V3 = yasuo2.transform.position; V3.z += 10; yasuo2.transform.position = V3;

        //yasuo2.AddComponent<Numeric> ();
        yasuo2.GetComponent <Numeric> ().id       = 2;
        yasuo2.GetComponent <Numeric>().tagString = blueTag;
        if (pp.P == 1)
        {
            yasuo2.AddComponent <P2> ();
            yasuo.AddComponent <PlayerController> ();
            //GameObject.FindWithTag ("MainCamera").transform = Red.parent;
        }
        else
        {
            yasuo.AddComponent <P2> ();
            yasuo2.AddComponent <PlayerController> ();
            //GameObject.FindWithTag ("MainCamera").transform = Blue.parent;
        }

        GameObject.FindWithTag("MainCamera").AddComponent <MainCameraControl> ();
        //Application.runInBackground = true;
        //net
        SendThread.start();
        ReceiveThread.start();

        GameObject baseRed = null, baseBlue = null;
        GameObject redBartizan1 = null, redBartizan2 = null, redBartizan3 = null;
        GameObject blueBartizan1 = null, blueBartizan2 = null, blueBartizan3 = null;

        Red.baseHome        = Resources.Load("Prefabs/Monster_base_red", typeof(GameObject));
        Red.bartizanPrefab  = Resources.Load("Prefabs/Monster_bartizan_red", typeof(GameObject));
        Blue.baseHome       = Resources.Load("Prefabs/Monster_base_blue", typeof(GameObject));
        Blue.bartizanPrefab = Resources.Load("Prefabs/Monster_bartizan_blue", typeof(GameObject));

        MakeObject("Untagged", Red.rotate, Red.bartDis0, Red.parent, Red.baseHome, ref baseRed);
        MakeObject("Untagged", Blue.rotate, Blue.bartDis0, Blue.parent, Blue.baseHome, ref baseBlue);
        //红塔
        MakeObject("Untagged", Red.rotate, Red.bartDis1, Red.parent, Red.bartizanPrefab, ref redBartizan1);
        MakeObject("Untagged", Red.rotate, Red.bartDis2, Red.parent, Red.bartizanPrefab, ref redBartizan2);
        MakeObject("Untagged", Red.rotate, Red.bartDis3, Red.parent, Red.bartizanPrefab, ref redBartizan3);
        //蓝塔
        MakeObject("Untagged", Blue.rotate, Blue.bartDis1, Blue.parent, Blue.bartizanPrefab, ref blueBartizan1);
        MakeObject("Untagged", Blue.rotate, Blue.bartDis2, Blue.parent, Blue.bartizanPrefab, ref blueBartizan2);
        MakeObject("Untagged", Blue.rotate, Blue.bartDis3, Blue.parent, Blue.bartizanPrefab, ref blueBartizan3);
    }