 Julia 中文文档242 CHAPTER 22. 网络和流 22.5 一个简单的 TCP 示例 让我们直接进入一个 TCP 套接字相关的简单示例。此功能位于名为 Sockets 的标准库中。让我们先 创建一个简单的服务器: julia> using Sockets julia> @async begin server = listen(2000) while true sock = accept(server) @0x00007fd31dc11ae0 对于那些熟悉 Unix 套接字 API 的人,这些方法名称会让人感觉很熟悉,可是它们的用法比原始的 Unix 套接字 API 要简单些。在本例中,首次调用 listen 会创建一个服务器,等待传入指定端口(2000)的 连接。 julia> listen(2000) # 监听(IPv4 下的)localhost:2000 Sockets.TCPServer(active) julia> 时,我们连接到刚刚创建的服务器。与此同时,accept 函数返回到新创建的套接字的服务 器端连接,并打印「Hello World」来表明连接成功。 Julia 的强大优势在于,即使 I/O 实际上是异步发生的,API 也以同步方式暴露,我们不必担心回调, 甚至不必确保服务器能够运行。在我们调用 connect 时,当前任务等待建立连接,并在这之后才继 续执行。在此暂停中,服务器任务恢复执行(因为现在0 码力 | 1238 页 | 4.59 MB | 1 年前3 Julia 中文文档242 CHAPTER 22. 网络和流 22.5 一个简单的 TCP 示例 让我们直接进入一个 TCP 套接字相关的简单示例。此功能位于名为 Sockets 的标准库中。让我们先 创建一个简单的服务器: julia> using Sockets julia> @async begin server = listen(2000) while true sock = accept(server) @0x00007fd31dc11ae0 对于那些熟悉 Unix 套接字 API 的人,这些方法名称会让人感觉很熟悉,可是它们的用法比原始的 Unix 套接字 API 要简单些。在本例中,首次调用 listen 会创建一个服务器,等待传入指定端口(2000)的 连接。 julia> listen(2000) # 监听(IPv4 下的)localhost:2000 Sockets.TCPServer(active) julia> 时,我们连接到刚刚创建的服务器。与此同时,accept 函数返回到新创建的套接字的服务 器端连接,并打印「Hello World」来表明连接成功。 Julia 的强大优势在于,即使 I/O 实际上是异步发生的,API 也以同步方式暴露,我们不必担心回调, 甚至不必确保服务器能够运行。在我们调用 connect 时,当前任务等待建立连接,并在这之后才继 续执行。在此暂停中,服务器任务恢复执行(因为现在0 码力 | 1238 页 | 4.59 MB | 1 年前3
 Julia 1.12.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 2009 页 | 6.72 MB | 1 年前3 Julia 1.12.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 2009 页 | 6.72 MB | 1 年前3
 julia 1.10.10com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3 julia 1.10.10com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.10.9com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3 Julia 1.10.9com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.8.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1463 页 | 5.01 MB | 1 年前3 Julia 1.8.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1463 页 | 5.01 MB | 1 年前3
 Julia 1.11.4com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.4com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia 1.11.5 Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.5 Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia v1.9.4 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3 Julia v1.9.4 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3
 Julia 1.9.0 DEV Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1633 页 | 5.23 MB | 1 年前3 Julia 1.9.0 DEV Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1633 页 | 5.23 MB | 1 年前3
 Julia 1.9.3 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3 Julia 1.9.3 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3
共 87 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9













