Example #1
0
        //Connetction close event.
        private void SocketConnectionClosed(object sender, EventArgs e)
        {
#if LUZEXI
            this.m_cUpdater._Close();
            this.m_cUpdater = null;
#endif
            Console.WriteLine("WebSocketConnection was terminated!");
        }
        private Action m_cOnSocketError;        //socket event

        /// <summary>
        /// Init this instance.
        /// </summary>
        internal static ClientUpdater Init(Action onConnect, Action onDisconnect, Action socketError, Action onUpdate)
        {
            GameObject    obj   = new GameObject("Socket");
            ClientUpdater trans = obj.AddComponent <ClientUpdater>();

            trans.m_cOnOpen        = onConnect;
            trans.m_cOnClose       = onDisconnect;
            trans.m_cOnSocketError = socketError;
            trans.m_cUpdate        = onUpdate;
            return(trans);
        }
Example #3
0
        //Init socket and make connection.
        public void init(Action onConnect, Action onDisconnect, Action onError)
        {
#if LUZEXI
            this.m_cUpdater = ClientUpdater.Init(onConnect, onDisconnect, onError, Update);
#endif
            this.socket.Opened  += this.SocketOpened;
            this.socket.Message += this.SocketMessage;
            this.socket.SocketConnectionClosed += this.SocketConnectionClosed;
            this.socket.Error += this.SocketError;

            this.socket.Connect();
        }