# Sending UDP message with backslash

**URL:** https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876
**Category:** General
**Created:** [17 July 2023 10:40 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876 "2023-07-17T10:40:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![chris3](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chris3](https://discourse.nodered.org/u/chris3)
#### Post date: [17 July 2023 10:40 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/1 "2023-07-17T10:40:40Z")

</div>

Hello,

I'm trying to send the following UDP message in Node-Red:

\apple

But the UDP message being received by the server is:

\\apple

I've been pulling my hair out for a couple of hours trying to come up with a fix and am still struggling. Could anyone help with a solution to this?

Chris

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [17 July 2023 15:04 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/2 "2023-07-17T15:04:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13db99e7168dc2ed578a1c35ff6b5bca1bc40c57.png)

just tried a simple test sending to/from same machine and that seems to work OK

Does a simple local test work for you?

---

<div class="post-metadata">

### Author: ![chris3](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chris3](https://discourse.nodered.org/u/chris3)
#### Post date: [17 July 2023 15:10 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/3 "2023-07-17T15:10:23Z")

</div>

Hi cymplecy,

This is the same behaviour as I get in the node-red gui. But when I recieve the packet in PacketSender an additional backslash has been added (screenshots below).

 ![Screenshot 2023-07-17 at 17.07.36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/238c5512949e1f962bd6b4bc4acca2cb3496b6dd.png)

 ![Screenshot 2023-07-17 at 17.07.45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11c52ed0985847c6c4c3e28235615e0f7f063daa.png)

I have, however come up with a solution in that I am using a function to generate the message in hex and then send it in hex. This has solved my problem and is giving the desired result:

```auto
var hexString = "5C6170706C65"; // Hexadecimal string to send
var buffer = Buffer.from(hexString, 'hex');
msg.payload = buffer;
return msg;

```

Chris

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 July 2023 15:46 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/4 "2023-07-17T15:46:08Z")

</div>

If you look at the Hex display in your screenshot you will see that the second `\` does not actually exist. My guess is that it is being escaped on the display. What does that display look like when you send it as hex?

---

<div class="post-metadata">

### Author: ![chris3](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@chris3](https://discourse.nodered.org/u/chris3)
#### Post date: [17 July 2023 15:58 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/5 "2023-07-17T15:58:41Z")

</div>

Well spotted!! I hadn't noticed that.

I'm sending the string as hex now and the ascii is displaying correctly with just the single backslash.

Chris

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 July 2023 16:00 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/6 "2023-07-17T16:00:50Z")

</div>

Interesting, and confusing.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [17 July 2023 18:22 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/7 "2023-07-17T18:22:57Z")

</div>

If you use the inject node to inject a string then it will escape the \ by adding another \ so `\apple` becomes `\\apple` - same as if you try to send `hello\n` to add a carriage return it will send `hello\\n` as a string... and not with a carriage return character that you want.

You can get round this by setting it to send Json (J) mode instead of String mode - as then `"\apple"` (now you have to add quotes as well to make it valid JSON) - will then get sent correctly

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 September 2023 18:23 UTC](https://discourse.nodered.org/t/sending-udp-message-with-backslash/79876/8 "2023-09-15T18:23:16Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
