プロデューサーが Python にあり、コンシューマーが Julia にある、Python と Julia を使用して基本的なクライアント サーバー ソケット構造を実装しようとしています。
Python 側の私のコードは次のようになります。
def startServer(host='127.0.0.1', port=4002):
connected = False
s = socket.socket()
s.bind((host, port))
s.listen(5)
scon, addr = s.accept()
print 'Got connection from', addr
return scon, addr
Julia 側では、次のようになります。
using PyCall
@pyimport server as sdlib
@async begin
sleep(10)
print("In the async thread\n")
s,a = sdlib.startServer("127.0.0.1",4002)
print("Server started\n")
end
print("After the async thread\n")
print("Connecting...\n")
connected = false
while !connected
try
connected = true
c = connect(4002)
print("Connected = $(connected), $(c)\n")
catch ex
print("$(ex)\n")
connected = false
sleep(1)
end
end
print("Connection established: $(c)\n")
出力は次のようになります。
After the async thread
Connecting...
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
connect: connection refused (ECONNREFUSED)
In the async thread
起こっているように見えるのは、Python リスナーが開始されるとすぐに、スレッドが接続を待機してロックすることです。クライアントが接続できるように、制御がメイン スレッドに戻されることはないようです。
これについて私が得ることができる助けに感謝します。
ありがとう、ラヴィ