public static NetDelegate GetIns() { if (m_ins != null) { return(m_ins); } m_ins = new NetDelegate(); return(m_ins); }
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(); }
//! connected done produce private void ConnectedDoneProc(bool _connected) { if (m_connectDoneDelegate != null) { m_connectDoneDelegate(_connected); if (_connected) { m_pulseSendCount = 0; m_connectDoneDelegate = null; } } }
// 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; }
// 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); }
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); })); } }
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; }
//通过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); } }
public void SetReconnectEvent(NetDelegate _event) { m_reconnectEvent = _event; }
public void ReleaseNetDelegateGCHandle(IntPtr handle) { NetDelegate.ReleaseGCHandle((GCHandle)handle); }
private void cancel_msg() { NetDelegate.GetIns().RemoveListener(HeaderConst.HEADER_LOGIN_MSG_ID, this.create_new_player); }
private void register_msg() { NetDelegate.GetIns().AddListener(HeaderConst.HEADER_LOGIN_MSG_ID, this.create_new_player); }
public void uinit() { NetDelegate.GetIns().RemoveListener(HeaderConst.HEADER_POS_MSG_ID); }
public void init() { NetDelegate.GetIns().AddListener(HeaderConst.HEADER_POS_MSG_ID, this.update_pos); }