/// <summary> /// 开始连接服务端 /// </summary> /// <param name="strHostNamePort">地址和端口</param> /// <returns></returns> public bool StartConnectServer(string strHostNamePort) { if (string.IsNullOrEmpty(strHostNamePort) == true) { throw new ArgumentException("Connecter.StartConnectServer(...) - string.IsNullOrEmpty(...) == true error!", "strHostNamePort"); } if (m_World == null) { throw new Exception("Connecter.StartConnectServer(...) - m_World == null error!"); } if (m_SocketClient.IsConnected == true) { throw new Exception("Connecter.StartConnectServer(...) - m_SocketClient.IsConnected == true error!"); } if (m_SocketClient.StartConnectServer(strHostNamePort) == true) { // 初始化Disposed m_LockDisposed.SetValid(); m_IsNeedSlice = true; LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.ConnecterString001, m_ClientSocketManager.Address); // 有新的连接出去需要发送全局信号处理新的连接 m_World.SetWorldSignal(); return(true); } return(false); }
/// <summary> /// 开始服务 /// </summary> /// <param name="port">端口</param> /// <returns></returns> public bool StartServer(uint port) { if (m_SocketServer.IsListened == true) { throw new Exception("Listener.StartServer(...) - m_SocketServer.IsConnected == true error!"); } if (m_SocketServer.StartServer(port) == true) { // 初始化Disposed m_LockDisposed.SetValid(); LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.ListenerString001, port); return(true); } else { return(false); } }
/// <summary> /// 开始运行客户端的处理 /// </summary> internal void Start() { // 断开处理在设置NetState时候检测 m_Running.SetValid(); m_Disposed.SetValid(); this.JoinWorld(); // 连接的通知事件 EventHandler <NetStateConnectEventArgs> tempEvent = m_EventConnect; if (tempEvent != null) { NetStateConnectEventArgs netStateConnectEventArgs = new NetStateConnectEventArgs(this); tempEvent(this, netStateConnectEventArgs); } // 设置NetState(需位于Start(...)函数之后),检查是否已断开与已收到新数据。 m_Socket.NetState = this; }