Exemplo n.º 1
0
 public static NetDelegate GetIns()
 {
     if (m_ins != null)
     {
         return(m_ins);
     }
     m_ins = new NetDelegate();
     return(m_ins);
 }
Exemplo n.º 2
0
        public void Can_create_delegate()
        {
            var invoked = false;
            var test    = new Action(() => { invoked = true; });

            using (var del = NetDelegate.FromDelegate(test))
            {
                del.Delegate.DynamicInvoke();
            }
            invoked.Should().BeTrue();
        }
Exemplo n.º 3
0
    //! connected done produce
    private void ConnectedDoneProc(bool _connected)
    {
        if (m_connectDoneDelegate != null)
        {
            m_connectDoneDelegate(_connected);

            if (_connected)
            {
                m_pulseSendCount      = 0;
                m_connectDoneDelegate = null;
            }
        }
    }
Exemplo n.º 4
0
 // This method is invoked when the application has loaded its UI and its ready to run
 public override bool FinishedLaunching (UIApplication app, NSDictionary options)
 {
     _ns = new NSNetService ("", "_bonjourdemoservice._tcp", UIDevice.CurrentDevice.Name, 9999);
     
     _netDel = new NetDelegate (this);
     
     _ns.Delegate = _netDel;
     
     //BUG: monotouch 3.3.1 has TXTRecordData incorrectly bound to a bool. will be fixed in v.Next
     //string message = "some message about the service...";     
     //_ns.TxtRecordData = NSData.FromString(message);
     
     _ns.Publish ();
     
     window.MakeKeyAndVisible ();
     
     return true;
 }
Exemplo n.º 5
0
        // This method is invoked when the application has loaded its UI and its ready to run
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            _ns = new NSNetService("", "_bonjourdemoservice._tcp", UIDevice.CurrentDevice.Name, 9999);

            _netDel = new NetDelegate(this);

            _ns.Delegate = _netDel;

            //BUG: monotouch 3.3.1 has TXTRecordData incorrectly bound to a bool. will be fixed in v.Next
            //var dictionary = NSDictionary.FromObjectAndKey (new NSString("some message about the service..."), new NSString ("someKey"));
            //var record = NSNetService.DataFromTxtRecord (dictionary);
            //_ns.TxtRecordData = record;

            _ns.Publish();

            window.MakeKeyAndVisible();

            return(true);
        }
Exemplo n.º 6
0
    public void BeginConnect(string host, int port, NetDelegate dele = null)
    {
        Debug.Log(string.Format("Begin Connect {0}:{1}", host, port));

        if (!m_connectingState)
        {
            m_serverHost = host;
            m_serverPort = port;

            m_connectDoneDelegate = dele;

            m_connectingState = true;
            StopAllCoroutines();
            StartCoroutine(StartConnect(m_serverHost, m_serverPort, delegate(bool _connected){
                m_connectingState = false;

                ConnectedDoneProc(_connected);
            }));
        }
    }
Exemplo n.º 7
0
    private IEnumerator StartConnect(string host, int port, NetDelegate del)
    {
        yield return(StartCoroutine(m_socket.StartConnect(host, port)));

        if (m_socket.Connected)
        {
            StopAllCoroutines();

            StartCoroutine(StartSend());
            StartCoroutine(StartReceive());

            m_reconnectInterval = 0;
        }

        if (null != del)
        {
            del(m_socket.Connected);
        }

        yield break;
    }
Exemplo n.º 8
0
 //通过hid发送对应的bytes给对应的监听者
 private void ParseHeader(int hLen)
 {
     lock (locker){
         int       ind;
         ArrayList arrL = Proto.unpack("iH", m_recvBytes, out ind);
         if (arrL == null || arrL.Count != 2)
         {
             return;
         }
         //Debug.Log("hLen is " + hLen);
         int    hid      = (ushort)arrL[1];
         byte[] tmpBytes = new byte[hLen];
         ind = ind - (int)Proto.calsize("H");
         Array.Copy(m_recvBytes, ind, tmpBytes, 0, hLen);
         int tot_len = hLen + (int)Proto.calsize("i");
         m_recvcount -= tot_len;
         byte[] tmp = new byte[m_recvcount];
         Array.Copy(m_recvBytes, tot_len, tmp, 0, m_recvcount);
         m_recvBytes = tmp;
         //发送数据
         Debug.Log("pass hid is " + hid);
         NetDelegate.GetIns().DispatchEvent((ushort)hid, tmpBytes);
     }
 }
Exemplo n.º 9
0
 public void SetReconnectEvent(NetDelegate _event)
 {
     m_reconnectEvent = _event;
 }
Exemplo n.º 10
0
 public void ReleaseNetDelegateGCHandle(IntPtr handle)
 {
     NetDelegate.ReleaseGCHandle((GCHandle)handle);
 }
Exemplo n.º 11
0
 private void cancel_msg()
 {
     NetDelegate.GetIns().RemoveListener(HeaderConst.HEADER_LOGIN_MSG_ID, this.create_new_player);
 }
Exemplo n.º 12
0
 private void register_msg()
 {
     NetDelegate.GetIns().AddListener(HeaderConst.HEADER_LOGIN_MSG_ID, this.create_new_player);
 }
Exemplo n.º 13
0
 public void uinit()
 {
     NetDelegate.GetIns().RemoveListener(HeaderConst.HEADER_POS_MSG_ID);
 }
Exemplo n.º 14
0
 public void init()
 {
     NetDelegate.GetIns().AddListener(HeaderConst.HEADER_POS_MSG_ID, this.update_pos);
 }