void BeginConnet() { try { // 同步连接 //LogMgr.Log("NewAddress:"+newHostname); //LogMgr.Log("NewAddress:"+newPort); //LogMgr.Log("NewAddressFamily:"+newAddressFamily.ToString()); if (m_connector != null) { m_connector.Abort(); m_connector = null; } m_tcpClient = new TcpClient(newAddressFamily); m_connector = new ConnectThread(m_tcpClient, newHostname, newPort, 5f); if (m_connector != null) { m_connector.Run(); } } catch (SocketException ex) { //LogMgr.LogError("SocketException:"+ex.Message); LogMgr.UnityWarning("_ConnectAsyncWithIp: exception " + ex.Message); // 异常的网络事件,发送断线重连事件 onError(ex.ErrorCode); } }
public void Connect(BluetoothDevice device) { if (state == STATE_CONNECTING) { if (connectThread != null) { connectThread.Cancel(); connectThread = null; } } // Cancel any thread currently running a connection if (connectedThread != null) { connectedThread.Cancel(); connectedThread = null; } // Start the thread to connect with the given device connectThread = new ConnectThread(device, this); connectThread.Run(); }