package com.webgame.as3.socket
{
    import com.webgame.as3.events.*;
    import flash.events.*;

    public class GameSocket extends EventDispatcher
    {
        private var jsonSocket:AMF3Socket;

        public function GameSocket(param1:String, param2:int)
        {
            this.jsonSocket = new AMF3Socket(null);
            this.jsonSocket.addEventListener(SocketDataEvent.SOCKET_CONNECT_OK_EVENT, this.socketConnectOK);
            this.connect(param1, param2);
            this.jsonSocket.addEventListener(SocketDataEvent.SOCKET_DATA_RECV_EVENT, this.socketRespnoe);
            this.jsonSocket.addEventListener(SocketDataEvent.SOCKET_CONNECT_FAIL_EVENT, this.socketConnectFail);
            this.jsonSocket.addEventListener(SocketDataEvent.SOCKET_CONNECT_CLOSE_EVENT, this.socketSendFail);
            return;
        }// end function

        public function connect(param1:String, param2:int) : void
        {
            this.jsonSocket.connect(param1, param2);
            return;
        }// end function

        public function send(param1:Object) : void
        {
            var _loc_2:Boolean = false;
            if (this.jsonSocket.connected)
            {
                _loc_2 = this.jsonSocket.send(param1);
            }
            return;
        }// end function

        private function socketConnectOK(event:SocketDataEvent) : void
        {
            dispatchEvent(new Event(Event.CONNECT));
            return;
        }// end function

        private function socketSendFail(event:SocketDataEvent) : void
        {
            return;
        }// end function

        private function socketConnectFail(event:SocketDataEvent) : void
        {
            dispatchEvent(event);
            return;
        }// end function

        private function socketRespnoe(event:SocketDataEvent) : void
        {
            dispatchEvent(event);
            return;
        }// end function

        public function get connected() : Boolean
        {
            return this.jsonSocket.connected;
        }// end function

    }
}
