Naive tcp chat server

Dear All!

For learning and practical purposes i tried to write a tcp server. It is supposed to accept multiple connections and provide capabilities of a chat server. I tried a number of things according to documentation examples and questions i could google here on Discourse or on StackOverflow. All my attempts so far failed badly.

Here is the simplest code (full version includes checks if sockets are still connected and sending the messages data to all sockets, but at first i need to solve the basic problems i experience at the moment) i could think of to get the capabilities i want (see some comments in the code):

using Dates
using Sockets
using DataStructures

const global not_shutdown = true
const global SOCKETS = Dict{TCPSocket,Int}()
const global buffer = Queue{String}()
const PORT = 4000
const LOCALIP = string(Sockets.getipaddr())
const welcome_msg = "Welcome!"

#it just checks if we got any messages from connected sockets
function server_loop()
	while not_shutdown
		if length(buffer) > 0
            @show buffer

function main()
	# Start the server asyncronously - this part works ok if i copypast the code into REPL, but does not work if i start the script as julia script.jl
	@async begin
		server = listen(PORT)
		while not_shutdown
			sock = accept(server)
			write(sock, welcome_msg)
			println("A new connection on socket $sock")
			push!(SOCKETS, sock => length(SOCKETS) +1)
			#@show SOCKETS
	println("TCP server is listening on $LOCALIP:$PORT")

    #a naive try to read data from sockets - i tried to put it into the server_loop(), but it does not work either
	@async begin
		global buffer
		while not_shutdown
			foreach(keys(SOCKETS)) do sock
				msg = String(bytesavailable(sock))

	#start the server loop

#running the server

So, i want my tcp server to accept connections and put sockets into a Dict. Next, i want to read from sockets and put the data somewhere - here i just tried a Queue. Definitely, i am doing things wrong, but can’t figure out the solution.
I would greatly appreciate any comments/edits on text, plus links to relevant information online that could help (could not find much on tcp julia server and numerous other related queries).

Many thanks in advance!