Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Socket code in Julia.
echo2_helper(socket,stat) =
begin
println(stat)
show(socket)
c = accept(socket)
println(c)
line = read_line(c)
println(line)
while line != "0\n"
write(c,line)
line = read_line(c)
end
close(c)
end
echo2(port::Int) =
begin
socket = listen(port)
socket.ccb = echo2_helper
end
julia> echo2(8000)
# methods for generic function echo2_helper
echo2_helper(socket,stat) at /home/leah/code/julia-websocket-server/websockets.jl:12
julia> 0
TcpSocket(connected,0 bytes waiting)ERROR: MemoryError()
in push! at array.jl:653
in wait at stream.jl:131
in readline at stream.jl:380
in echo2_helper at /home/leah/code/julia-websocket-server/websockets.jl:18
in _uv_hook_connectioncb at stream.jl:159
in event_loop at multi.jl:1386
in anonymous at client.jl:281ERROR: in tasknotify: work not defined
in tasknotify at stream.jl:104
in _uv_hook_readcb at stream.jl:208
in event_loop at multi.jl:1386
in anonymous at client.jl:281ERROR: in tasknotify: work not defined
in tasknotify at stream.jl:104
in _uv_hook_readcb at stream.jl:208
in event_loop at multi.jl:1386
in anonymous at client.jl:281
echo(client) = (args...) -> begin
line = readline(client)
write(client,line)
if line != "0\n"
return true
end
close(client)
false
end
echo_server(port::Int) =
listen(port) do sock,stat
client = accept(sock)
client.readcb = echo(client)
start_reading(client)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment