Please help with TCP Chat Server example

It’s too vague. If you have actual real world (not made up to proof your point) examples of where you need to convert from Slice to String and then back we might be able to show idiomatic and/or performant alternatives or clear up some misunderstanding. But so far this sounds more like FUD than anything else to be honest.

What the hell are you talking about? You’re making a lot of assumptions to me! My English must be too bad or it’s bad spirit from your par or the both.

If you reread without any FUD paranoia or point of view, you’ll see that I’m just looking for an example in Crystal to process messages directly with Bytes. The problem is that all the Crystal examples I see deal with strings. No? In this topic while message = client.gets is a String, right? The final socket message is send in Bytes, right?

Look in the code io, socket and string, you’ll see the conversions of that. It’s normal for string message.

It’s not to criticize Crystal, all programming languages offer to deal with string or bytes (uint8 slice or equivalent), including Crystal. It’s nice, except that I was looking for examples and I’m receive a trial of intent (FUD, examples not made up to proof my point, etc).

Stop feeling like you’re under attack, I’m looking for a solution, not the debate, not gratuitous attacks like you do.

With Go I handle the message in Bytes (not string) with https://golang.org/pkg/bufio/ (helper on top of the reader and writer)

I’m looking for equivalent in Crystal but it’s boring, I give up. I’ll do this part in Rust.

Have a look at https://crystal-lang.org/api/0.34.0/IO.html

Reading a bunch of bytes is as simple as

buff = Bytes.new(BUFF_SIZE)
bytes_read = io.read(buff)
do_stuff_to(buff[0, bytes_read])

There currently is no primitive to read an arbitrary amount of bytes up to a delimiter repeatedly. We assume low level consumers prefer to work with fixed size reusable buffers and high level consumers that care about a delimiter want a string anyways.

There’s IO::Delimited as a one time read up to a delimiter primitive:

io = IO::Delimited.new(io, read_delimiter: "\n")
bytes_read = io.read(buff)

So in theory you could rewrap the underyling IO each time the delimiter is hit (each time IO::Delimited signals EOF), but admittedly this is not the usecase it is intended for.

Ok thanks for the explanation.