public static ZPollItem Create(ReceiveDelegate receiveMessage, SendDelegate sendMessage) { var pollItem = new ZPollItem((receiveMessage != null ? ZPoll.In : ZPoll.None) | (sendMessage != null ? ZPoll.Out : ZPoll.None)); pollItem.ReceiveMessage = receiveMessage; pollItem.SendMessage = sendMessage; return pollItem; }
public MessageBusInputChannel( BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent, EndpointAddress localAddress, IBus bus) : base(bufferManager, encoder, parent) { _localAddress = localAddress; _bus = bus; _aLock = new object(); _tryReceiveDelegate = (TimeSpan timeout, out Message message) => { message = null; try { var requestMessage = _bus.Receive(true, null); if (requestMessage != null) { message = GetWcfMessageFromString(requestMessage.Content); OnAfterTryReceive(requestMessage); } } catch (Exception ex) { throw new CommunicationException(ex.Message, ex); } return true; }; _receiveDelegate = (TimeSpan timeout) => { var requestMessage = _bus.Receive(false, ChannelID); return GetWcfMessageFromString(requestMessage.Content); }; }
public void Run() { MessageItemData msgitem; try { msgitem._num = int.Parse(this._view.prev_int.Text); msgitem._dnum = double.Parse(this._view.prev_double.Text); msgitem._todo = new double[3]; msgitem._todo[0] = double.Parse(this._view.prev_double1.Text); msgitem._todo[1] = double.Parse(this._view.prev_double2.Text); msgitem._todo[2] = double.Parse(this._view.prev_double3.Text); msgitem.strTest = this._view.prev_string.Text; msgitem.isRun = Boolean.Parse(this._view.prev_boolean.Text); Boolean bRet = _Send(msgitem); if (bRet) { Console.WriteLine("\n\n--------- C# 전송한 결과값 성공적으로 리턴됨 -----------\n\n\n"); } else { Console.WriteLine("\n\n\n--------- C# 마샬링 실패함. -----------\n\n\n"); } receive_delegate = _Receive; _Init(receive_delegate); } catch (Exception e) { Console.WriteLine(e); System.Windows.MessageBox.Show("정확한 데이터를 입력하십시오!"); } }
public void CreateChannel(ReceiveDelegate r) { args = null; Receiver += r; CreateInstanceChannel(); }
public bool IsSingle(string guid, ReceiveDelegate r) { s_Guid = guid; Receiver += r; return(IsSingle()); }
private void SendCommand(byte[] cmd, int receiveCnt, ReceiveDelegate receiveDelegate) { if (connection_ != null) { connection_.SendReceiveRequest(cmd, receiveCnt, new BaseConnectionHandler(this, receiveDelegate)); } }
public static ZPollItem Create(ReceiveDelegate receiveMessage, SendDelegate sendMessage) { var pollItem = new ZPollItem((receiveMessage != null ? ZPollEvent.In : ZPollEvent.None) | (sendMessage != null ? ZPollEvent.Out : ZPollEvent.None)); pollItem.ReceiveMessage = receiveMessage; pollItem.SendMessage = sendMessage; return(pollItem); }
public bool IsSingle(string guid, int port, ReceiveDelegate r) { s_Guid = guid; s_Port = port; Receiver += r; return(IsSingle()); }
/// <summary> /// 构造函数 /// </summary> public DoubleChannelClient() { isOpen = false; connectDelegate = Connect; sendByChannel1Delegate = SendByChannel1; sendByChannel2Delegate = SendByChannel2; receiveByChannel1Delegate = ReceiveByChannel1; receiveByChannel2Delegate = ReceiveByChannel2; }
static bool _Init(ReceiveDelegate del) { bool bRet = false; // 방법 2 : 델리게이트를 전달하고 C++ Dll 에서 해당 델리게이트를 실행하여 업데이트 bRet = NativeMethods.Init(del); return(bRet); }
/// <summary> /// Registers a call back function to execute when command line arguments are received from another instance of the application. /// </summary> /// <param name="del">The delegate to execute upon receiving command line arguments.</param> public static void RegisterReceiveEvent(ReceiveDelegate del) { // Initialize a server channel to listen on the specified port tcpChannel = new TcpChannel(port); // Register as a well known service so other intances of this application can get a proxy to interact with this singleton controller ChannelServices.RegisterChannel(tcpChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(SingletonController), typeof(SingletonController).Name, WellKnownObjectMode.SingleCall); Receiver += del; }
/// <summary> /// Constructor /// </summary> public Inbox(IMailServerConfiguration mailServerConfiguration) { if (mailServerConfiguration == null) { throw new MailServerConfigurationMissingException(); } _serverConfiguration = mailServerConfiguration; StartPollingQueue(); _asyncReceive = new ReceiveDelegate(Receive); }
/// <summary> /// 构造函数 /// </summary> /// <param name="channelHandler">通道的数据包处理器</param> /// <param name="monitor">数据包处理器监测器</param> internal SingleChannelClient(IPacketHandler channelHandler, IPacketMonitor monitor) { this.channelHandler = channelHandler; isOpen = true; key = channelHandler.Key; iv = channelHandler.IV; this.monitor = monitor; connectDelegate = Connect; sendDelegate = Send; receiveDelegate = Receive; }
public Message EndReceive(IAsyncResult result) { System.Runtime.Remoting.Messaging.AsyncResult aresult = result as System.Runtime.Remoting.Messaging.AsyncResult; if (aresult == null) { throw new ArgumentException("Invalid IAsyncResult type"); } ReceiveDelegate d = aresult.AsyncDelegate as ReceiveDelegate; return(d.EndInvoke(result)); }
public static bool IamFirst(ReceiveDelegate callback) { if (IamFirst()) { Receiver += callback; return(true); } else { return(false); } }
public static bool IamFirst(ReceiveDelegate r) { if (IamFirst()) { Receiver += r; return true; } else { return false; } }
private async Task Receive() { if (Receive_RichTextBox.InvokeRequired) { var d = new ReceiveDelegate(ReceiveMessage); Receive_RichTextBox.BeginInvoke(d); } else { await ReceiveMessage(); } }
public static bool IamFirst(ReceiveDelegate r) { if (IamFirst()) { Receiver += r; return(true); } else { return(false); } }
public static void InitializeDelegates() { delCreate = Create; delReceive = Receive; delDestroy = Destroy; delStart = Start; InitializeDelegatesOnNative(Marshal.GetFunctionPointerForDelegate(delCreate), Marshal.GetFunctionPointerForDelegate(delReceive), Marshal.GetFunctionPointerForDelegate(delDestroy), Marshal.GetFunctionPointerForDelegate(delStart)); }
/// <summary> /// Creates the game world and establishes a connection with the server. /// </summary> void StartConnect() { // Make new world TheWorld = new World(1000, 1000); // Delagate called when connection is made ReceiveDelegate ReceiveCallBack = new ReceiveDelegate(Receive); Socket NewSocket = Network.Connect_to_Server(ReceiveCallBack, ServerTextBox.Text); TheState = new Network_Controller.PreservedState(NewSocket, ReceiveCallBack); }
/// <summary> /// 构造函数 /// </summary> /// <param name="channelHandler1">通道1的数据包处理器</param> /// <param name="channelHandler2">通道2的数据包处理器</param> /// <param name="monitor">数据包处理器监测器</param> internal DoubleChannelClient(IPacketHandler channelHandler1, IPacketHandler channelHandler2, IPacketMonitor monitor) { this.channelHandler1 = channelHandler1; this.channelHandler2 = channelHandler2; isOpen = true; key = channelHandler1.Key; iv = channelHandler1.IV; this.monitor = monitor; connectDelegate = Connect; sendByChannel1Delegate = SendByChannel1; sendByChannel2Delegate = SendByChannel2; receiveByChannel1Delegate = ReceiveByChannel1; receiveByChannel2Delegate = ReceiveByChannel2; }
//public HoloClient(int port_) //{ // this.port = port_; //} public void Init(int port_, ReceiveDelegate callb) { this.port = port_; this.delegateHandler = callb; #if UNITY_WSA_10_0 && !UNITY_EDITOR socket = new DatagramSocket(); socket.MessageReceived += SocketOnMessageReceived; socket.BindServiceNameAsync(port.ToString()).GetResults(); #else udp = new UdpClient(port); //StartCoroutine("receiveMsg"); //_recvT = new Thread(receiveMsg); //_recvT.Start(); udp.BeginReceive(new AsyncCallback(receiveMsg), null); #endif }
private void SendSetNextPosCommand(float sp, Int32 ts, byte dst, ReceiveDelegate receiveDelegate) { byte[] spBytes = BitConverter.GetBytes(sp); if (connection_ != null) { SendCommand(connection_, new byte[] { (byte)'N', dst, spBytes[0], spBytes[1], spBytes[2], spBytes[3], (byte)ts, (byte)(ts >> 8), (byte)(ts >> 16), (byte)(ts >> 24) }, 8, receiveDelegate); } }
void Init() { if (isserver) { udpclient = new UdpClient(ServerPort); } else { //udpclient = new UdpClient( serveraddress, ServerPort ); IPAddress[] ipaddresses = Dns.GetHostAddresses(serveraddress); remoteserverendpoint = new IPEndPoint(ipaddresses[0], serverport); udpclient = new UdpClient(); } receivedelegate = new ReceiveDelegate(udpclient.Receive); asyncresult = null; }
private void TODeliver(int en) { log(en, string.Format("[TODeliver] start")); lock (_TOWaitingLock) { lock (_TOQueueLock) { var x = _TOWaiting.Select(m => string.Format("({0},{1})", m.topic, m.seqnum)); log(en, string.Format("[TODeliver] TOWaiting:{0}", string.Join(",", x))); var y = _TOQueue.Select(n => string.Format("({0},{1})", n.topic, n.seqnum)); log(en, string.Format("[TODeliver] TOQueue:{0}", string.Join(",", y))); _TOWaiting = _TOWaiting.OrderBy(m => m.seqnum).ToList(); _TOQueue = _TOQueue.OrderBy(m => m.seqnum).ToList(); while (_TOQueue.Count != 0 && _TOWaiting.Count != 0) { var msg = _TOQueue[0]; var upt = _TOWaiting[0]; if (msg.seqnum != upt.seqnum) break; _TOQueue.RemoveAt(0); _TOWaiting.RemoveAt(0); lock (_topicSubscribers) { foreach (var subscribedTopic in _topicSubscribers.Keys) { if (!equivalentTopic(msg.topic, subscribedTopic)) continue; foreach (var subUri in _topicSubscribers[subscribedTopic]) { log(en, string.Format("[TODeliver] sent to {0}", subUri)); var sub = _uriToSubs[subUri]; ReceiveDelegate rd = new ReceiveDelegate(sub.receive); msg.seqnum = _TOSubscriberFIFO[subUri]++; rd.BeginInvoke(msg, null, null); } } } } x = _TOWaiting.Select(m => string.Format("({0},{1})", m.topic, m.seqnum)); log(en, string.Format("[TODeliver] TOWaiting:{0}", string.Join(",", x))); y = _TOQueue.Select(n => string.Format("({0},{1})", n.topic, n.seqnum)); log(en, string.Format("[TODeliver] TOQueue:{0}", string.Join(",", y))); } } }
/// <summary> /// Constructor /// </summary> public Inbox() { StartPollingQueue(); _asyncReceive = new ReceiveDelegate(Receive); }
private void deliver(int en, PublishMessage rmsg) { var msg = new PublishMessage(rmsg, _site); // to avoid sending two times, we use a list List<string> sentURIs = new List<string>(); // Dictionary of delegates per subcribers Dictionary<string, ReceiveDelegate> remoteDelegate = new Dictionary<string, ReceiveDelegate>(); List<string> receivingSubscribers = new List<string>(); // First phase we filter site subscribers and fillin lock (_topicSubscribers) { foreach (var subscribedTopic in _topicSubscribers.Keys) { if (!equivalentTopic(msg.topic, subscribedTopic)) continue; if (_orderingPolicy == OrderingPolicy.total) { lock (_TOQueue) { _TOQueue.Add(msg); } break; } foreach (var uri in _topicSubscribers[subscribedTopic]) // subscriber uri { if (receivingSubscribers.Contains(uri)) continue; receivingSubscribers.Add(uri); } } } if (_orderingPolicy == OrderingPolicy.total) { TODeliver(en); return; } foreach (var uri in receivingSubscribers) { Subscriber s = _uriToSubs[uri]; // TODO assync ReceiveDelegate rd = new ReceiveDelegate(s.receive); if (_orderingPolicy == OrderingPolicy.fifo) { lock (_subToFifoStruct) { if (!_subToFifoStruct.ContainsKey(uri)) { _subToFifoStruct.Add(uri, new List<FIFOstruct>()); } int index = _subToFifoStruct[uri].FindIndex(item => item._publhisherURI == msg.publisherURI); if (index < 0) { // element does not exists _subToFifoStruct[uri].Add(new FIFOstruct(msg.publisherURI, 0)); //getIndex Now index = _subToFifoStruct[uri].FindIndex(item => item._publhisherURI == msg.publisherURI); } var fifo = _subToFifoStruct[uri][index]; //create a new message for each site interested sites with possibly a different seqnum var x = msg.seqnum; msg.seqnum = fifo._seq_num; fifo._seq_num++; log(en, string.Format("FIFO Deliver.For subscriber {2} mapping seqnum from {0} to {1}", x, msg.seqnum, uri)); rd.BeginInvoke(msg, null, null); } } else { // No ordering log(en, "NO ordering. no seqnum mapping"); rd.BeginInvoke(msg, null, null); log(en, string.Format("Delivered message to {0}", uri)); } } }
void Init() { if( isserver ) { udpclient = new UdpClient( ServerPort ); } else { //udpclient = new UdpClient( serveraddress, ServerPort ); IPAddress[] ipaddresses = Dns.GetHostAddresses( serveraddress ); remoteserverendpoint = new IPEndPoint( ipaddresses[0], serverport ); udpclient = new UdpClient(); } receivedelegate = new ReceiveDelegate(udpclient.Receive); asyncresult = null; }
public void setReceiveOut(ReceiveDelegate receive) { receiveOut = receive; }
private void deliver(PublishMessage msg) { // to avoid sending two times, we use a list List<string> sentUris = new List<string>(); // List of delegates that know the interested subcribers List<ReceiveDelegate> remoteDelegates = new List<ReceiveDelegate>(); // First phase we filter site subscribers and fillin lock (_topicSubscribers) { foreach (var subscribedTopic in _topicSubscribers.Keys) { if (!equivalentTopic(msg.topic, subscribedTopic)) continue; foreach (var uri in _topicSubscribers[subscribedTopic]) { if (sentUris.Contains(uri)) continue; Subscriber s = _uriToSubs[uri]; // TODO assync ReceiveDelegate rd = new ReceiveDelegate(s.receive); remoteDelegates.Add(rd); //MUDAR ISTO... // c.reportEvent(EventType.SubEvent, uri, msg.publisherURI, msg.topic, msg.total_seqnum); log(string.Format("[Deliver] sent event '{0}' to '{1}'", msg, uri)); } } } List<IAsyncResult> results = new List<IAsyncResult>(); foreach (ReceiveDelegate subDelegate in remoteDelegates) { IAsyncResult result = subDelegate.BeginInvoke(msg, null, null); results.Add(result); } List<WaitHandle> handlesLst = new List<WaitHandle>(); //TODO ASK PROFESSOR IF WE NEED TO RESEND LOST MESSAGES }
public BaseConnectionHandler(TestForm parent, ReceiveDelegate receiveDelegate, SerialConnection connection) { parent_ = parent; receiveDelegate_ = receiveDelegate; connection_ = connection; }
private void SendCommand(SerialConnection connection, char cmd, int receiveCnt, ReceiveDelegate receiveDelegate) { if (connection != null) { connection.SendReceiveRequest(new byte[] { (byte)cmd }, receiveCnt, new BaseConnectionHandler(this, receiveDelegate, connection)); } }
internal static extern bool Init(ReceiveDelegate del);
private void SendCommand(ConnectionData connectionData, char cmd, int receiveCnt, ReceiveDelegate receiveDelegate) { if (connectionData != null && connectionData.connection_ != null) { connectionData.connection_.SendReceiveRequest(new byte[] { (byte)cmd }, receiveCnt, new BaseConnectionHandler(this, receiveDelegate, connectionData.connection_)); } }
public BaseConnectionHandler(ScopeDSCClient parent, ReceiveDelegate receiveDelegate, SerialConnection connection) { parent_ = parent; receiveDelegate_ = receiveDelegate; connection_ = connection; }
public void Delegate_Init(ReceiveDelegate _Receive_Delegate, ErrorDelegate _Error_Delegate) { Receive_Delegate = _Receive_Delegate; Error_Delegate = _Error_Delegate; }
public static ZPollItem Create(ReceiveDelegate receiveMessage) { return(Create(receiveMessage, null)); }
public void Receive( ReceiveDelegate receiveCallback ) { m_Client.BeginReceive( new AsyncCallback( ReceiveResult ), receiveCallback ); }
public static ZPollItem Create(ReceiveDelegate receiveMessage) { return Create(receiveMessage, null); }
/// <summary> /// 开始异步接收 /// </summary> /// <param name="requestCallBack">当接收一帧数据的回调函数</param> public IAsyncResult BeginReceive(AsyncCallback requestCallBack) { if (this.IsRuning) { //把Recive函数实例化为一个ReceiveDelegate(上面已定义好)的委托 ReceiveDelegate dl = new ReceiveDelegate(Receive); //调用委托的BeginInvoke开始异步接收,第一个参数为异步完成回调函数,第二个参数是传线回调函数的对象 IAsyncResult ar = dl.BeginInvoke(requestCallBack, dl); return ar; } else { return null; } }