// Get the next protected WorldEvent NextEvent() { string data = Encoding.UTF8.GetString(world.Receive()); Console.WriteLine("received: `{0}`", data); string[] e = data.Split(" ".ToCharArray()); var worldEvent = new WorldEvent(); worldEvent.type = Event.Default; worldEvent.properties = null; if (e[0] == id && e[1] == "new") { // This message has the format: // <hash> new // id <id> // <key0> <value0> // <key1> <value1> // ... // (Not including newlines -- formatted for readability) // This is building that dictionary to pass to the script // so it can update from the network. Debug.Assert(e.Length >= 4); worldEvent.properties = new Dictionary <string, string>(); for (int i = 2; i < e.Length; i += 2) { worldEvent.properties[e[i]] = e[i + 1]; } } return(worldEvent); }
internal void UDPReciever() { try { timerforchecklogin = new System.Timers.Timer(); timerforchecklogin.Interval = 30000; timerforchecklogin.Start(); timerforchecklogin.Elapsed += timerforchecklogin_Elapsed; Task.Factory.StartNew(() => { while (true) { // string address = subscriber.Receive (Encoding.Unicode); // byte[] buffer = new byte[512]; // int bufferSize = subscriber.Receive (buffer); var buffer = subscriber.Receive(); if (buffer == null) { this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("STOP")); continue; } FinalPrice _obj = (FinalPrice)DataPacket.RawDeserialize(buffer.Skip(4).Take(buffer.Length - 4).ToArray(), typeof(FinalPrice)); // Console.WriteLine("Received"); // if(_obj.Token==37454) // Console.Title="Token: "+_obj.Token+", Bid: "+_obj.MAXBID+", Ask: "+_obj.MINASK+" LTP: "+_obj.LTP; // else// if (_obj.Token==66039) // Console.WriteLine("Token {0} Bid {1} Ask {2} LTP {3}",_obj.Token,_obj.MAXBID,_obj.MINASK,_obj.LTP); if (_obj.Token == 111) { Console.WriteLine(" SomeThing Wrong in DATA Server"); this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("START")); // OnDataError.Invoke(); continue; } if (_iSubscribe.Contains(_obj.Token)) { this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("START")); OnDataArrived.Raise(OnDataArrived, OnDataArrived.CreateReadOnlyArgs(_obj)); } } }); } catch (OperationCanceledException e) { Console.WriteLine("Cancellation invoked"); } catch (AggregateException e) { Console.WriteLine("Some unexpected exception "); } catch (Exception Ex) { Console.WriteLine("Exception Raised " + Ex.StackTrace); } }
internal void UDPReciever() { try { timerforchecklogin = new System.Timers.Timer(); timerforchecklogin.Interval = 30000; timerforchecklogin.Start(); timerforchecklogin.Elapsed += timerforchecklogin_Elapsed; Task.Factory.StartNew(() => { while (true) { // string address = subscriber.Receive (Encoding.Unicode); // byte[] buffer = new byte[512]; // int bufferSize = subscriber.Receive (buffer); var buffer = subscriber.Receive(); if (buffer == null) { this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("STOP")); continue; } FinalPrice _obj = (FinalPrice)DataPacket.RawDeserialize(buffer.Skip(4).Take(buffer.Length - 4).ToArray(), typeof(FinalPrice)); if (_obj.Token == 111) { Console.WriteLine(" SomeThing Wrong in DATA Server"); this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("START")); // OnDataError.Invoke(); continue; } if (_iSubscribe.Contains(_obj.Token)) { UDP_RecieverData.Instance.TokenData.AddOrUpdate(_obj.Token, _obj, (k, v) => _obj); } } }); } catch (OperationCanceledException e) { Console.WriteLine("Cancellation invoked"); } catch (AggregateException e) { Console.WriteLine("Some unexpected exception "); } catch (Exception Ex) { Console.WriteLine("Exception Raised " + Ex.StackTrace); } }
public void Check() { var data = sub.Receive(); // data is null when timed out if (data != null) { var list = UnpackToMap(data, this.config.Params, ref Params); // broadcast for each key changed (expect a single item in the list) foreach (var key in list) { Changed(this, key); } } }
public static void Execute(string[] args) { string[] values = args; if (values.Length != 3) { throw new ArgumentException("Invalid number parameters."); } switch (values[1].Trim().ToLower()) { case "publisher": using (var s = new PublishSocket()) { s.Bind(values[2]); int i = 0; while (true) { byte[] b = Encoding.ASCII.GetBytes("Publish Counter is " + ++i); s.Send(b); Console.Write("."); Thread.Sleep(2000); } } break; case "subscriber": using (var s = new SubscribeSocket()) { //Needs to match the first portion of the message being received. s.Subscribe("Publish Counter"); s.Connect(values[2]); while (true) { byte[] b = s.Receive(); if (b != null) { Console.WriteLine("Received: " + Encoding.ASCII.GetString(b)); } else { Console.WriteLine("x"); } } } break; } }
public void Execute() { byte[] buffer; while (true) { Console.WriteLine("Listening..."); try { buffer = _socket.Receive(); var message = DBUpdateMessage.Decode(buffer); Console.WriteLine("\t[" + message.ServerId + "] Received command '" + message.Command + "' for key: " + message.Key); ProceedWriteCommand(message); Console.WriteLine("\tOK"); } catch { Console.WriteLine("Catch exception in subscriber"); } } }
public static void Execute() { Console.WriteLine("Executing pubsub test "); int receiveCount = 0; var clientThread = new Thread( () => { var subscriber = new SubscribeSocket(); subscriber.Connect(InprocAddress); subscriber.Subscribe("TestMessage"); byte[] streamOutput = new byte[BufferSize]; while (true) { var sw = Stopwatch.StartNew(); for (int i = 0; i < Iter; i++) { int read = 0; streamOutput = subscriber.Receive(); read = streamOutput.Length; //using (var stream = subscriber.ReceiveStream()) // while (stream.Length != stream.Position) // { // read += stream.Read(streamOutput, 0, streamOutput.Length); // var message = Encoding.ASCII.GetString(streamOutput, 0, read); // Trace.Assert(message.StartsWith("TestMessage")); // // break; // } ++receiveCount; } sw.Stop(); var secondsPerSend = sw.Elapsed.TotalSeconds / (double)Iter; Console.WriteLine("Time {0} us, {1} per second, {2} mb/s ", (int)(secondsPerSend * 1000d * 1000d), (int)(1d / secondsPerSend), (int)(DataSize * 2d / (1024d * 1024d * secondsPerSend))); } }); clientThread.Start(); { var publisher = new PublishSocket(); publisher.Bind(InprocAddress); Thread.Sleep(100); var sw = Stopwatch.StartNew(); int sendCount = 0; var text = "TestMessage" + new string('q', 10); var data = Encoding.ASCII.GetBytes(text); while (sw.Elapsed.TotalSeconds < 10) { publisher.Send(data); ++sendCount; } Thread.Sleep(100); clientThread.Abort(); Console.WriteLine("Send count {0} receive count {1}", sendCount, receiveCount); publisher.Dispose(); } }
internal void UDPReciever() { try { timerforchecklogin = new System.Timers.Timer(); timerforchecklogin.Interval = 30000; timerforchecklogin.Start(); timerforchecklogin.Elapsed += timerforchecklogin_Elapsed; Task.Factory.StartNew(() => { while (true) { // string address = subscriber.Receive (Encoding.Unicode); // byte[] buffer = new byte[512]; // int bufferSize = subscriber.Receive (buffer); var buffer = subscriber.Receive(); if (buffer == null) { this.OnDataStatusChange.Raise(OnDataStatusChange, OnDataStatusChange.CreateReadOnlyArgs("STOP")); continue; } //Data = (INTERACTIVE_ONLY_MBP)DataPacket.RawDeserialize(buffer.Skip(4).ToArray(), typeof(INTERACTIVE_ONLY_MBP)); long TokenName = BitConverter.ToInt64(buffer, 0); Data = (INTERACTIVE_ONLY_MBP)DataPacket.RawDeserialize(buffer.Skip(8).ToArray(), typeof(INTERACTIVE_ONLY_MBP)); OnDataChange.Raise(OnDataChange, OnDataChange.CreateReadOnlyArgs(Data)); //if (Global.Instance.Data_With_Nano.ContainsKey(TokenName)) //{ // switch(Global.Instance.Data_With_Nano[TokenName]) // { // case ClassType.MARKETWTCH: // Data = (INTERACTIVE_ONLY_MBP)DataPacket.RawDeserialize(buffer.Skip(8).ToArray(), typeof(INTERACTIVE_ONLY_MBP)); // OnDataChange.Raise(OnDataChange, OnDataChange.CreateReadOnlyArgs(Data)); // break; // case ClassType.SPREAD: // SpreadData_7211 = (MS_SPD_MKT_INFO_7211)DataPacket.RawDeserialize(buffer.Skip(8).ToArray(), typeof(MS_SPD_MKT_INFO_7211)); // OnSpreadDataChange.Raise(OnSpreadDataChange, OnSpreadDataChange.CreateReadOnlyArgs(SpreadData_7211)); // break; // } //} } }); } catch (OperationCanceledException e) { Console.WriteLine("Cancellation invoked"); } catch (AggregateException e) { Console.WriteLine("Some unexpected exception "); } catch (Exception Ex) { Console.WriteLine("Exception Raised " + Ex.StackTrace); } }