我问了如何让TCP服务器在这里始终发送数据:Julia TCP select它工作的很好。我现在有新的问题,所以我想开始新的谈话。Julia TCP服务器和连接
所以发件人有时会发送一些服务器1和服务器1读取它和更新发送什么服务器2和服务器2计算的数字和以C通信程序。
这里是我的服务器1个代码:
notwaiting = true
message = zeros(10,14)
server = listen(5001)
connection = connect(5003)
while true
if notwaiting
notwaiting = false
# Runs accept async (does not block the main thread)
@async begin
sock = accept(server)
reply= read(sock, Float64, 11)
message[:,convert(Int64,reply[1])] = reply[2:11]
write(connection,reshape(message,140))
global notwaiting = true
end
end
write(connection,reshape(message,140))
if message[1,1] == -1.0
close(connection)
close(server)
break
end
sleep(0.01) # slow down the loop
end
发件人是:
Connection2= connect(5001)
message = [2.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0]
write(Connection2,message)
close(Connection2)
和服务器2是这样的:
function Server2_connection()
println("Waiting for connection")
server2 = listen(5003)
conn_2 = accept(server2)
while isopen(conn_2)
try
message_server2 = round(read(conn_2,Float64,140),3)
ins_matrix = reshape(message_server2[1:140],10,14)
catch e
println("caught an error $e")
break
end
end
println("Connection closed")
close(conn)
close(server)
end
问题是,一切融合在一起是真的重。我的意思是我可以从发件人发送2封邮件,一切都运行得非常慢。我可以运行整个事情10-15s然后它冻结。所有的连接工作,但真的很慢。我的问题是我错过了什么或者有什么让服务器真的很慢?我怎样才能更好地编码?
你没有使用[Julia的并行工具](http://docs.julialang.org/en/latest/manual/parallel-computing/)进行远程调用/远程评估的任何特定原因? –
我无法重现缓慢或冻结(运行测试约5分钟并发送10条消息)。我在Windows系统上运行所有运行Julia 0.5 + rc3的程序进行了测试,结果没有任何缓慢。即使将server2移动到Mac(通过Wi-Fi网络连接)服务器1和2运行正常。也许这是一个版本或环境的问题? (例如:操作系统,硬件,网络,...) – Gomiero
你的意思是?你可以更具体地解释你是什么意思@FelipeLema –