Problem processing TCP CONNECT REFUSED in Julia

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 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..

The Julia code to connect to the IQFeed client is:

function socket_init()
    Display("At socket_init.")
        # Connect to the server and display socket and peer details
        inet_addr = Sockets.InetAddr(IPv4(""), 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")

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.


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

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

You’re ignoring any other error types, consider