Problem with simple "echo" client/server

Ok - this is not multithreaded or anything, just a simple “echo” server and client (just baby steps - trying to understand simple before I move on from there). I start the server first, then the client in a different shell. The server gets the message, and seems to send it back, but the client never gets it?
Server:

using Sockets

port = 9999
echo_server = listen(port)

while true
    @info "starting server"
    sock = accept(echo_server)
    @info "accepted: $(getsockname(sock))"
    message = read(sock, String)
    @info "read message: '$message'"
    write(sock, message)
    @info "message sent"
    close(sock)
end

Client:

using Sockets

s = connect(9999)
@info "connected"
write(s, "hi there")
@info "message sent"
m = read(s, String)
println(m)
@info "got back: '$m'"
close(s)

The issue that read(io, String) tries to read everything into a String. Where is the end?

Try this instead.

Server:

using Sockets

port = 9999
echo_server = listen(port)

while true
    @info "starting server"
    sock = accept(echo_server)
    @info "accepted: $(getsockname(sock))"
    message = readline(sock)
    @info "read message: '$message'"
    println(sock, message)
    @info "message sent"
    close(sock)
end

Client:

using Sockets

s = connect(9999)
@info "connected"
println(s, "hi there")
@info "message sent"
m = readline(s)
println(m)
@info "got back: '$m'"
close(s)

Thanks, I guess I didn’t consider how the server would figure the end of a String … perhaps it would have worked with an integer type, but your solution worked and made sense.