# Problem processing TCP CONNECT REFUSED in Julia

**URL:** <https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096>\
**Category:** Web Stack\
**Created:** [April 29, 2023, 6:26pm UTC](https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096 "2023-04-29T18:26:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Brauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charles_brauer/32/48688_2.png) [@Charles\_Brauer](https://discourse.julialang.org/u/Charles_Brauer)\
**Post date:** [April 29, 2023, 6:26pm UTC](https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096/1 "2023-04-29T18:26:14Z")

</div>

Hey Guys,

I am trying to convert some C# code that processes real-time data streaming of financial data.

My application uses the TCP socket-based client from [https://www.IQFeed.net](https://www.IQFeed.net) to receive the data during market hours. My Julia version works fine when the IQFeed client is running on my Windows 11 machine.

My source code for the Julia version is at [GitHub - CBrauer/IQFeed-julia: Process real-time streaming data from the major stock exchanges.](https://github.com/CBrauer/IQFeed-julia).

The Julia code to connect to the IQFeed client is:

```julia
function socket_init()
    Display("At socket_init.")
    try
        # Connect to the server and display socket and peer details
        inet_addr = Sockets.InetAddr(IPv4("127.0.0.1"), 5009)
        global socket = Sockets.connect(inet_addr)
        sockname = getsockname(socket)
        peername = getpeername(socket)
        Display("ip $(sockname[1]), port $(sockname[2])")
        Display("ip $(peername[1]), port $(peername[2])")
        Display("socket has been initialized.")
    catch err
        if err.code == Base.UV_ECONNREFUSED
            Display("Error in initializing the socket: $err")
        end
    end
end

```

Here is my problem. If IQFeed.exe is not running, I do not get a connection refused error in my try/catch block. Why not?

How can I catch the TCP socket connect problem gracefully.?

Any suggestions will be greatly appreciated.

Charles

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 30, 2023, 12:16am UTC](https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096/2 "2023-04-30T00:16:38Z")

</div>

I’m not sure what your `Display` function does or why it is capitalized, but the following, replacing `Display` with `@error`, does seem to report an error for me.

```julia
julia> try
           using Sockets
           inet_addr = Sockets.InetAddr(IPv4("127.0.0.1"), 5009)
           Sockets.connect(inet_addr)
       catch err
           if err.code == Base.UV_ECONNREFUSED
               @error "Error in intializing the socket: $err"
           end
       end
┌ Error: Error in intializing the socket: Base.IOError("connect: connection refused (ECONNREFUSED)", -111)
└ @ Main REPL[12]:6

```

---

<div class="post-metadata">

**Author:** ![Charles\_Brauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charles_brauer/32/48688_2.png) [@Charles\_Brauer](https://discourse.julialang.org/u/Charles_Brauer)\
**Post date:** [April 30, 2023, 1:34am UTC](https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096/3 "2023-04-30T01:34:31Z")

</div>

> [@mkitti](#):
>
> `@error "Error in intializing the socket: $err"`

Thanks mkitti. That was the problem. I fixed my “display” function and now it works.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [April 30, 2023, 1:36am UTC](https://discourse.julialang.org/t/problem-processing-tcp-connect-refused-in-julia/98096/4 "2023-04-30T01:36:23Z")

</div>

You’re ignoring any other error types, consider

```julia
else
  rethrow(err)

```
