# Issues running two TCP servers

**URL:** https://discourse.julialang.org/t/issues-running-two-tcp-servers/60807
**Category:** General Usage
**Created:** [May 9, 2021, 6:50am UTC](https://discourse.julialang.org/t/issues-running-two-tcp-servers/60807 "2021-05-09T06:50:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ligert123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ligert123/32/24682_2.png) [@ligert123](https://discourse.julialang.org/u/ligert123)
#### Post date: [May 9, 2021, 6:50am UTC](https://discourse.julialang.org/t/issues-running-two-tcp-servers/60807/1 "2021-05-09T06:50:35Z")

</div>

Hello, i am currently trying to run 2 TCP servers, one that will encrypt itself using MbedTLS and the other that will not.  
An issue i am having is that when a socket is opened on one of the servers and it is waiting to time out neither server can take more requests. I looked into the accept code and i see there is an iolock, could that be causing this?

```julia
    function loop(port, db)
        server = Sockets.listen(port)
        control_channel = Channel(10)
        task = @async begin
            while true
                if(isready(control_channel))
                    val = take!(control_channel)
                    if(val == false)
                        break
                    end
                end
                conn = Sockets.accept(server)
                @debug "Accepted " conn
                @async begin
                    @debug "Connection Start"
                    state = 0
                    time_start = 0
                    while true
                        if(processConnection(conn, db) )
                            state = 0

                        else
                            if(state == 0)
                                time_start = now()
                                state = 1
                            elseif(state == 1)
                                if(now() - time_start >= Minute(1))
                                    @debug "Connection Timeout." conn
                                    break

                                end
                            end
                        end
                        sleep(0.1)
                    end
                end
            end
            close(server)
        end
        return server, control_channel
    end
    function loopSecure(port, db)
        server = Sockets.listen(port)
        control_channel = Channel(10)
        task = @async begin
            while true
                if(isready(control_channel))
                    val = take!(control_channel)
                    if(val == false)
                        break
                    end
                end
                conn = Sockets.accept(server)
                @debug "Accepted " conn
                @async begin
                    @debug "Secure Connection Start"
                    entropy = MbedTLS.Entropy()
                    rng = MbedTLS.CtrDrbg()
                    MbedTLS.seed!(rng, entropy)
                    ctx = MbedTLS.SSLContext()
                    conf = MbedTLS.SSLConfig()
        
                    MbedTLS.config_defaults!(conf)
                    MbedTLS.authmode!(conf, MbedTLS.MBEDTLS_SSL_VERIFY_REQUIRED)
                    MbedTLS.rng!(conf, rng)
                    MbedTLS.ca_chain!(conf)
                    MbedTLS.setup!(ctx, conf)
                    MbedTLS.set_bio!(ctx, conn)
                    MbedTLS.handshake(ctx)

                    state = 0
                    time_start = 0
                    while true
                        if(processConnection(conn, db) )
                            state = 0
                        else
                            if(state == 0)
                                time_start = now()
                                state = 1
                            elseif(state == 1)
                                if(now() - time_start >= Minute(1))
                                    @debug "Connection Timeout." conn
                                    break

                                end
                                
                            end
                        end
                        sleep(0.1)
                    end
                end
            end
            close(server)
        end
        return server, control_channel
    end

```

---

<div class="post-metadata">

### Author: ![ligert123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ligert123/32/24682_2.png) [@ligert123](https://discourse.julialang.org/u/ligert123)
#### Post date: [May 9, 2021, 7:28am UTC](https://discourse.julialang.org/t/issues-running-two-tcp-servers/60807/2 "2021-05-09T07:28:14Z")

</div>

I may have just solved it and another issue by switching to use “accept\_nonblocking”
