public void Connect() { if (Connecting || Connected) { return; } _Connecting = true; client = new TcpClient { Client = null }; sendQueue.Clear(); receiveThread = new Thread(() => { InternalConnect(); }); receiveThread.IsBackground = true; receiveThread.Start(); #if SLEEPY_STATS System.Timers.Timer statsFlush = new System.Timers.Timer(1000); statsFlush.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { stats.Flush(); }; statsFlush.AutoReset = true; statsFlush.Enabled = true; #endif }
/// <summary> /// Connects to the game server with the given <see cref="ConnectArgs"/>. /// This should be called from the main Unity thread. /// </summary> /// <param name="connectArgs"></param> public void Connect(ConnectArgs connectArgs) { if (isConnecting || IsConnected) { return; } InitializeFields(connectArgs); userId = UnityEngine.Random.Range(0, int.MaxValue); isConnecting = true; RaiseConnecting(); // Instantiating with new TcpClient(url, port) will immediately // try to connect and block. Simply instantiate and connect // in the receive background thread when it starts so the // main Unity thread doesn't hang. client = new TcpClient(); client.Client = null; // Clear the queues when connecting instead of disconnecting // in case you want to still process packets that were received. receivePacketsQueue.Clear(); sendPacketsQueue.Clear(); receivePacketsThread = new Thread(() => { ReceivePacketsThread(connectArgs); }); receivePacketsThread.IsBackground = true; receivePacketsThread.Start(); }
/// <summary> /// IDispose satisfaction /// </summary> public virtual void Dispose() { try { logger.Debug(string.Format("Disposing {0} ... ", threadName)); if (samplesQ != null) { samplesQ.Clear(); } qEvent.Close(); evtTerminate.Close(); qEvent = null; evtTerminate = null; eventHandles = null; if (udp != null) { udp.Close(); } } catch (Exception e) { logger.Exception(e); } }
public void Stop() { // 작업 쓰레드 중지 if (m_receiverThread != null) { m_receiverRun = false; m_receiverThread.Join(TimeSpan.FromSeconds(10.0)); if (m_receiverThread.ThreadState == ThreadState.WaitSleepJoin || m_receiverThread.ThreadState == ThreadState.Running) { m_receiverThread.Abort(); } m_receiverThread = null; } m_messageQueue.Clear(); m_key = null; m_receivedSeqFlags.Clear(); m_resetIndexForReceivedSeqFlags = -this.Sender.MaxBackupSequence / 2; // 리셋 m_socket = null; }
/// <summary> ///Clear 的测试 ///</summary> public void ClearTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 target.Clear(); Assert.Inconclusive("无法验证不返回值的方法。"); }
private void RestartThread(bool clearQueue) { m_creationLock.WaitOne(); AbortThread(true); if (clearQueue) { m_queue.Clear(); } Initialize(); StartThread(); m_creationLock.Release(); }
public void Stop() { m_messageQueue.Clear(); // 작업 쓰레드 중지 m_senderRun = false; if (m_senderThread != null) { this.StopThread(m_senderThread); m_senderThread = null; } if (m_backupCheckThread != null) { this.StopThread(m_backupCheckThread); m_backupCheckThread = null; } // 리셋 m_socket = null; }
public void ClearQueues() { receivePacketsQueue?.Clear(); outboundPacketsQueue?.Clear(); }
virtual protected void ClearQueue() { mSendDataList.Clear(); mBufferData.Clear(); mResultDataList.Clear(); }