private void OnMessageReceived(object sender, UdpSocketMessageReceivedEventArgs e) { try { switch (Networking.GetServiceType(e.ByteData)) { case ServiceType.ConnectionResponse: ProcessConnectResponse(e.ByteData); break; case ServiceType.ConnectionStateResponse: ProcessConnectionStateResponse(e.ByteData); break; case ServiceType.TunnelingAck: ProcessTunnelingAck(e.ByteData); break; case ServiceType.DisconnectRequest: ProcessDisconnectRequest(e.ByteData); break; case ServiceType.TunnelingRequest: ProcessDatagramHeaders(e.ByteData); break; } } catch (Exception ex) { if (IsDebug) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
private void OnMessageReceived(object sender, UdpSocketMessageReceivedEventArgs e) { var from = String.Format("{0}:{1}", e.RemoteAddress, e.RemotePort); var data = Encoding.UTF8.GetString(e.ByteData, 0, e.ByteData.Length); Messages.Add(new UDPMessage(){Value = data}); Debug.WriteLine("{0} - {1}", @from, data); RaisePropertyChanged(() => Messages); }
internal async void RunMessageReceiver(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var didReceive = false; var msg = new UdpReceiveResult(); try { // attempt to read next datagram msg = await _backingUdpClient .ReceiveAsync() .WrapNativeSocketExceptions(); didReceive = true; } catch { // exception may occur because we stopped listening // (i.e. cancelled the token) - if so exit loop // otherwise throw. if (!cancellationToken.IsCancellationRequested) throw; } if (!didReceive) return; // cancelled, exit loop; // generate the message received event var remoteAddress = msg.RemoteEndPoint.Address.ToString(); var remotePort = msg.RemoteEndPoint.Port.ToString(); var data = msg.Buffer; var wrapperArgs = new UdpSocketMessageReceivedEventArgs(remoteAddress, remotePort, data); // fire if (MessageReceived != null) MessageReceived(this, wrapperArgs); } }
private void OnMessageReceived(object sender, UdpSocketMessageReceivedEventArgs e) { try { KnxDatagram knxDatagram; switch(DatagramProcessing.ProcessDatagram(e.ByteData, ThreeLevelGroupAddressing, IsDebug, out knxDatagram)) { case ResponseType.Event: base.EventReceived(knxDatagram.DestinationAddress, knxDatagram.Data); break; case ResponseType.Status: base.StatusReceived(knxDatagram.DestinationAddress, knxDatagram.Data); break; } } catch(Exception ex) { if(IsDebug) { System.Diagnostics.Debug.WriteLine(ex.Message); } } }
private void MessageReceived(object sender, UdpSocketMessageReceivedEventArgs e) { if (ReceivedBytes != null) { var eventArgs = new ReceivedBytesEventArgs { ConnectionType = ConnectionTypes.Udp }; ReceivedBytes(e.ByteData, eventArgs); } }
internal async void DatagramMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var remoteAddress = args.RemoteAddress.CanonicalName; var remotePort = args.RemotePort; byte[] allBytes; var stream = args.GetDataStream().AsStreamForRead(); using (var mem = new MemoryStream()) { await stream.CopyToAsync(mem); allBytes = mem.ToArray(); } var wrapperArgs = new UdpSocketMessageReceivedEventArgs(remoteAddress, remotePort, allBytes); if (MessageReceived != null) MessageReceived(this, wrapperArgs); }
private void OnMessageReceived(object sender, UdpSocketMessageReceivedEventArgs e) { if(MessageReceived != null) MessageReceived(sender, new DatagramReceivedEventArgs(e.RemoteAddress, int.Parse(e.RemotePort), e.ByteData)); }
private void MessageReceivedCallback(object sender, UdpSocketMessageReceivedEventArgs ev) { string serializedResponse = Encoding.UTF8.GetString(ev.ByteData, 0, ev.ByteData.Length); var response = JsonConvert.DeserializeObject<ServerResponse>(serializedResponse); MessagingCenter.Send(this, "ReceivedServerResponse", response); }