Example #1
0
        public void _onConnectionState(ConnectState state)
        {
            KBEngine.Event.deregisterIn(this);

            bool success = (state.error == "" && valid());

            if (success)
            {
                Dbg.DEBUG_MSG(string.Format("NetworkInterface::_onConnectionState(), connect to {0} is success!", state.socket.RemoteEndPoint.ToString()));
                _packetReceiver = new PacketReceiver(this);
                _packetReceiver.startRecv();
                connected = true;
            }
            else
            {
                reset();
                Dbg.ERROR_MSG(string.Format("NetworkInterface::_onConnectionState(), connect error! ip: {0}:{1}, err: {2}", state.connectIP, state.connectPort, state.error));
            }

            Event.fireAll("onConnectionState", new object[] { success });

            if (state.connectCB != null)
            {
                state.connectCB(state.connectIP, state.connectPort, success, state.userData);
            }
        }
Example #2
0
        public void _onConnectStatus(ConnectState state)
        {
            KBEngine.Event.deregisterIn(this);

            bool success = (state.error == "" && valid());

            if (success)
            {
                Dbg.DEBUG_MSG(string.Format("NetworkInterface::_onConnectStatus(), connect to {0} is success!", state.socket.RemoteEndPoint.ToString()));
                _packetReceiver = new PacketReceiver(this);
                _packetReceiver.startRecv();
            }
            else
            {
                Dbg.ERROR_MSG(string.Format("NetworkInterface::_onConnectStatus(), connect is error! ip: {0}:{1}, err: {2}", state.connectIP, state.connectPort, state.error));
            }

            LuaFramework.Util.CallMethod("Event", "Brocast", new object[] { "onConnectStatus", success });
            //Event.fireOut("onConnectStatus", new object[]{success});

            if (state.connectCB != null)
            {
                state.connectCB(state.connectIP, state.connectPort, success, state.userData);
            }
        }
 public void reset()
 {
     if (valid())
     {
         _socket.Close(0);
     }
     _socket         = null;
     _packetReceiver = null;
     _packetSender   = null;
 }
		public void reset()
		{
			if(valid())
			{
         	   _socket.Close(0);
			}
			_socket = null;
			_packetReceiver = null;
			_packetSender = null;
		}
Example #5
0
 public void reset()
 {
     if (valid())
     {
         Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
         _socket.Close(0);
     }
     _socket         = null;
     _packetReceiver = null;
     _packetSender   = null;
 }
        public void reset()
        {
            if (valid())
            {
                _socket.Close(0);
            }
            _socket         = null;
            _packetReceiver = null;
            _packetSender   = null;

            _connectIP   = "";
            _connectPort = 0;
            _connectCB   = null;
            _userData    = null;
        }
Example #7
0
 static int packetReceiver(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         KBEngine.NetworkInterface obj = (KBEngine.NetworkInterface)ToLua.CheckObject <KBEngine.NetworkInterface>(L, 1);
         KBEngine.PacketReceiver   o   = obj.packetReceiver();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #8
0
        private static void _onRecv(IAsyncResult ar)
        {
            // Retrieve the socket from the state object.
            PacketReceiver state = (PacketReceiver)ar.AsyncState;

            try
            {
                // 由于多线程问题,networkInterface可能已被丢弃了
                // 例如:在连接loginapp之后自动开始连接到baseapp之前会先关闭并丢弃networkInterface
                if (!state.networkInterface().valid())
                {
                    return;
                }

                Socket client = state.networkInterface().sock();

                // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    // 更新写位置
                    Interlocked.Add(ref state._wpos, bytesRead);
                    state.startRecv();
                }
                else
                {
                    if (bytesRead == 0)
                    {
                        Dbg.WARNING_MSG(string.Format("PacketReceiver::_processRecved(): disconnect!"));
                        Event.fireIn("_closeNetwork", new object[] { state.networkInterface() });
                        return;
                    }
                    else
                    {
                        state.startRecv();
                    }
                }
            }
            catch (Exception e)
            {
                Dbg.ERROR_MSG(string.Format("PacketReceiver::_processRecved(): is error({0})!", e.ToString()));
                Event.fireIn("_closeNetwork", new object[] { state.networkInterface() });
            }
        }
        public void reset()
        {
            _packetReceiver = null;
            _packetSender   = null;
            _filter         = null;
            connected       = false;

            if (_socket != null)
            {
                if (_socket.RemoteEndPoint != null)
                {
                    Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
                }

                _socket.Close(0);
                _socket = null;
            }
        }
		public void _onConnectStatus(ConnectState state)
		{
			KBEngine.Event.deregisterIn(this);
			
			bool success = (state.error == "" && valid());
			if(success)
			{
				Dbg.DEBUG_MSG(string.Format("NetworkInterface::_onConnectStatus(), connect to {0} is success!", state.socket.RemoteEndPoint.ToString()));
				_packetReceiver = new PacketReceiver(this);
				_packetReceiver.startRecv();
			}
			else
			{
				Dbg.ERROR_MSG(string.Format("NetworkInterface::_onConnectStatus(), connect is error! ip: {0}:{1}, err: {2}", state.connectIP, state.connectPort, state.error));
			}
			
			Event.fireOut("onConnectStatus", new object[]{success});
			
			if (state.connectCB != null)
				state.connectCB(state.connectIP, state.connectPort, success, state.userData);
		}
        public void _onConnectStatus(string error)
        {
            KBEngine.Event.deregisterIn(this);

            bool success = (error == "");

            if (success)
            {
                Dbg.INFO_MSG(string.Format("NetworkInterface::_onConnectStatus(), connected to {0}", sock().RemoteEndPoint.ToString()));
                _packetReceiver = new PacketReceiver(this);
                _packetReceiver.startRecv();
            }
            else
            {
                Dbg.ERROR_MSG(string.Format("NetworkInterface::_onConnectStatus(), connect is error! ip: {0}:{1}, err: {2}", _connectIP, _connectPort, error));
            }

            Event.fireAll("onConnectStatus", new object[] { success });

            if (_connectCB != null)
            {
                _connectCB(_connectIP, _connectPort, success, _userData);
            }
        }
 public void reset()
 {
     if(valid())
     {
         Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
      	   _socket.Close(0);
     }
     _socket = null;
     _packetReceiver = null;
     _packetSender = null;
 }