Hi all,
I am aware that this is an old topic but I just cannot seem to wrap my head around this. I am reading data sent to me through a socket connection. The data is just this simple thing:
{“timestamp”: “data”}
Over the wire (wireshark) I can see I am getting something like this:
{“2019-11-22 16:14:12”:“00450”}… (dots included)
As expected (well not really but I can understand the why) Elixir displays it as:
<<32, 123, 34, 50, 48, 49, 57, 45, 49, 49, 45, 50, 50, 32, 49, 54, 58, 50, 57, etc…
Is there a function to or library to extrat the ASCII?
I am borrowing this piece of code: https://gist.github.com/cblavier/9ff624d9afd3cdc5671786cfeefeb6ae
Which I am trying to use as:
def handle_info({:tcp, socket, packet}, state) do
packet_str = StringUtil.raw_binary_to_string(packet)
Logger.info("#{inspect(packet_str)}\n")
{:noreply, state}
end
But so far no success. Am I doing something wrong? I know I can always map the binary to the ASCII equivalent but I really do not want to do that if I can avoid it.
Thanks,