# Communication between julia and python using TCP socket

**URL:** https://discourse.julialang.org/t/communication-between-julia-and-python-using-tcp-socket/32146
**Category:** New to Julia
**Tags:** question
**Created:** [December 11, 2019, 12:09pm UTC](https://discourse.julialang.org/t/communication-between-julia-and-python-using-tcp-socket/32146 "2019-12-11T12:09:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![HiroIshida](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hiroishida/32/7424_2.png) [@HiroIshida](https://discourse.julialang.org/u/HiroIshida)
#### Post date: [December 11, 2019, 12:09pm UTC](https://discourse.julialang.org/t/communication-between-julia-and-python-using-tcp-socket/32146/1 "2019-12-11T12:09:57Z")

</div>

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

```julia
# 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

```

```julia
# 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.

```julia
# 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:

```julia
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)

```

---

<div class="post-metadata">

### Author: ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)
#### Post date: [December 11, 2019, 12:20pm UTC](https://discourse.julialang.org/t/communication-between-julia-and-python-using-tcp-socket/32146/2 "2019-12-11T12:20:53Z")

</div>

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