# Non-blocking network IO

**URL:** <https://discourse.julialang.org/t/non-blocking-network-io/123344>\
**Category:** General Usage\
**Created:** [December 2, 2024, 7:43am UTC](https://discourse.julialang.org/t/non-blocking-network-io/123344 "2024-12-02T07:43:35Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [December 18, 2024, 8:06pm UTC](https://discourse.julialang.org/t/non-blocking-network-io/123344/26 "2024-12-18T20:06:16Z")

</div>

> [@Sukera](#):
>
> Julia doesn’t currently have non-blocking I/O

As was true in 2017 from the link in OP’s post, and still remains true today, Julia uses non-blocking I/O for all streams, since Julia is green threaded (uses Tasks instead of threads):

> [@How to read from socket in non-blocking mode](https://discourse.julialang.org/t/how-to-read-from-socket-in-non-blocking-mode/4710/3):
>
> All I/O in julia is non-blocking in the traditional sense of the word, because we don’t block threads on I/O activity. However, we do use tasks to simulate blocking I/O for ease of programming. The nb\_available function isn’t super meaningful for sockets. It tells you how many bytes are available in the userspace buffer. It says nothing about now many bytes are available in the kernel, in various buffers along the network path or are in transit.

@phma the answers to all of your questions will be the same: use a task in some form (`@async` or `Threads.@spawn` are the most common) and write synchronous-looking code. It will automatically be converted into a non-blocking form internally (through the benefit of Tasks). When you are done with the socket (e.g. because it was told to shutdown) call `close` on all sockets that you want to destroy from any task.

---

_[View the full topic](https://discourse.julialang.org/t/non-blocking-network-io/123344)._
