sockets - Julia TCP select -


i have 1 problem tcp connection.

i have made server like:

 server = listen(5000)   sock = accept(server)     while isopen(sock)      yes=read(sock,float64,2)      println(yes)    end 

i want continually print [0.0,0.0] when there nothing read, otherwise print reads server. go loop(trying read something), if there nothing read or crashes. try task like:

begin  server = listen(5000)  while true    sock = accept(server)     while isopen(sock)      yes=read(sock,float64,2)      println(yes)    end   println([0.0,0.0])  end end 

but print reads. i'm making connection other console , ride through consol:

clientside=connect(5000) write(clientside,[2.0,2.0]) 

so i'm trying make server prints [0.0,0.0], if there nothing read , print reads when there read. ideas?

maybe, 1 strategy make server run accept / print block asynchronously (since accept call blocks main thread).

following tutorial "using tcp sockets in julia", 1 way make server is:

notwaiting = true server = listen(5000) while true       if notwaiting         notwaiting = false         # runs accept async (does not block main thread)         @async begin             sock = accept(server)             ret = read(sock, float64, 2)             println(ret)             global notwaiting = true         end             end     println([0.0, 0.0])     sleep(1) # slow down loop end 

the variable notwaiting makes async block runs once per connection (without it, server runs kind of "race condition").

testing 2 calls client program, produces following output:

c:\research\stackoverflow\en-us>julia s.jl [0.0,0.0] [0.0,0.0] [0.0,0.0] [0.0,0.0] [2.0,2.0] [0.0,0.0] [0.0,0.0] [0.0,0.0] [2.0,2.0] [0.0,0.0] [0.0,0.0] [0.0,0.0] 

tested julia version 0.5.0-rc3+0


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -