# How to send bytes by UDP?

**URL:** <https://forum.crystal-lang.org/t/how-to-send-bytes-by-udp/2030>\
**Category:** Help & Support\
**Created:** [May 1, 2020, 2:45pm UTC](https://forum.crystal-lang.org/t/how-to-send-bytes-by-udp/2030 "2020-05-01T14:45:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darenw](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/darenw/32/647_2.png) [@darenw](https://forum.crystal-lang.org/u/darenw)\
**Post date:** [May 1, 2020, 2:45pm UTC](https://forum.crystal-lang.org/t/how-to-send-bytes-by-udp/2030/1 "2020-05-01T14:45:50Z")

</div>

I thought I’d whip up a simple quick command line program to send bytes by UDP to test some other software. Turns out not to be as quick as I was hoping. The server.send method has trouble compiling.

```
In /usr/lib/crystal/socket.cr:298:26
 298 | evented_send(message.to_slice, "Error sending datagram") do |slice|
                            ^-------
Error: undefined method 'to_slice' for Array(UInt8)

```

The source code, stripped to essentials, is:

```
  alias Byte = UInt8
  cat48data : Array(Byte) = Byte[11, 22, 33, 44]

  server = UDPSocket.new
  server.bind "192.168.11.23", 

  while command!='q' 
    server.send cat48data
  end
```

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [May 1, 2020, 3:33pm UTC](https://forum.crystal-lang.org/t/how-to-send-bytes-by-udp/2030/2 "2020-05-01T15:33:53Z")

</div>

The easiest solution is probably to use a byte slice instead of an array: `Bytes[11, 22, 33, 44]`

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [May 1, 2020, 11:13pm UTC](https://forum.crystal-lang.org/t/how-to-send-bytes-by-udp/2030/3 "2020-05-01T23:13:56Z")

</div>

Also if you need something similar to an array in that you can easily manipulate it then IO::Memory is super useful and it has a `to_slice` method. Also deals with endianness
