コード例 #1
0
        /// <summary>
        /// 连接web服
        /// </summary>
        public long ConnectTo(string host, BaseNet.OnConnectedFunction connected, BaseNet.OnReceiveFunction receive, BaseNet.OnCloseFunction close)
        {
            WebNetConnecter socket = new WebNetConnecter();

            socket.Setup();
            socket.conn_idx = ++m_share_conn_idx;
            m_connectedes.Add(socket.conn_idx, socket);
            socket.Connect(host, connected, receive, close);
            return(socket.conn_idx);
        }
コード例 #2
0
        public bool Listen(string host, BaseNet.OnAcceptFunction accept, BaseNet.OnReceiveFunction receive, BaseNet.OnCloseFunction close)
        {
            OnAccept  = accept;
            OnReceive = receive;
            OnClose   = close;

            m_socket            = new WebServerSocket();
            m_socket.OnOpen    += OnAcceptConnect;
            m_socket.OnMessage += OnMessageReveived;
            m_socket.OnClose   += OnConnectClose;
            return(m_socket.Start(host));
        }
コード例 #3
0
        public long Connect(string host, BaseNet.OnConnectedFunction connected, BaseNet.OnReceiveFunction receive, BaseNet.OnCloseFunction close)
        {
            OnConnected = connected;
            OnReceive   = receive;
            OnClose     = close;

            m_socket            = new WebClientSocket();
            m_socket.OnOpen    += OnAcceptConnect;
            m_socket.OnMessage += OnMessageReveived;
            m_socket.OnClose   += OnConnectClose;
            m_socket.Connect(host);

            return(m_conn_idx);
        }
コード例 #4
0
        /// <summary>
        /// 连接主机
        /// </summary>
        public long ConnectTo(string ip, ushort port, BaseNet.OnConnectedFunction connected, BaseNet.OnReceiveFunction receive, BaseNet.OnCloseFunction close)
        {
            TCPNetConnecter socket = new TCPNetConnecter();

            socket.Setup();
            socket.conn_idx = ++m_share_conn_idx;
            m_connectedes.Add(socket.conn_idx, socket);
            //之所以延迟到下帧执行,可以防止上层逻辑还没有加入到集合,就已经连接成功返回
            TimerManager.Instance.AddNextFrame((timer_id, param) => { socket.Connect(ip, port, connected, receive, close); });
            return(socket.conn_idx);
        }
コード例 #5
0
 /// <summary>
 /// 内部调用或底层触发
 /// </summary>
 public virtual void Close()
 {
     OnReceive = null;
     OnClose   = null;
 }