Communication between julia and python using TCP socket

The following echo server and client written in Julia work well.

# server written in Julia
using Sockets 
server = listen(ip"127.0.0.1", 2000)
sock = accept(server)
while true
    write(sock, "echo: " * readline(sock) * "\n")
end
# client written in Julia
using Sockets 
clientside=connect(2000)
println(clientside,"abc") 
println(readline(clientside))

However, when I write client side in python as below and tried to connect it to server written in Julia, it didn’t worked and hanged up on tcp_client.rect(1024). It would be really helpful I could get some hint to solve this problem.

# client written in python
import socket

target_ip = "127.0.0.1"
target_port = 2000

tcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_client.connect((target_ip,target_port))
tcp_client.send(b"abc")
response = tcp_client.recv(1024)
print(response)

For your information, the client written in python works well with the following server written in python:

import socket

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 2000        # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)
1 Like

Try sending a \n as well in clientside python, in julia readline expects it before returning.

2 Likes