swift-nio | driven network application framework for high performance | Networking library

 by   apple Swift Version: 2.54.0 License: Apache-2.0

kandi X-RAY | swift-nio Summary

kandi X-RAY | swift-nio Summary

swift-nio is a Swift library typically used in Networking applications. swift-nio has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

SwiftNIO is a cross-platform asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. It's like Netty, but written for Swift.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              swift-nio has a medium active ecosystem.
              It has 7392 star(s) with 606 fork(s). There are 190 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 139 open issues and 502 have been closed. On average issues are closed in 237 days. There are 50 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of swift-nio is 2.54.0

            kandi-Quality Quality

              swift-nio has 0 bugs and 0 code smells.

            kandi-Security Security

              swift-nio has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              swift-nio code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              swift-nio is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              swift-nio releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of swift-nio
            Get all kandi verified functions for this library.

            swift-nio Key Features

            No Key Features are available at this moment for swift-nio.

            swift-nio Examples and Code Snippets

            No Code Snippets are available at this moment for swift-nio.

            Community Discussions

            QUESTION

            Is is possible to open SwiftNIO based server socket within XCTest test app?
            Asked 2021-Dec-22 at 10:17

            I have an XCTest which works with UI components. I tried to open a server socket within the xctext function using SwiftNIO.

            I took the echo server example from here. and I simplified, removed the args with hardcoded values for the sake of a dirty test.

            ...

            ANSWER

            Answered 2021-Dec-22 at 10:17

            Yes, that is possible, you can find many examples of this in the AsyncHTTPClient and SwiftNIO test suites.

            The reason that yours doesn't work is because you shut down the MultiThreadedEventLoopGroup right after binding the socket. So essentially you're starting everything up and then you shut it down again.

            Also, for unit tests, I'd recommend binding to 127.0.0.1 only because you probably don't want connections from elsewhere. Another good idea is to use an ephemeral port, ie. have the system pick a free, random port automatically. You can achieve this by specifying port 0. After you bind the server Channel you can then interrogate the server channel by using serverChannel.localAddress?.port! about the port it picked.

            Here's a full example with a client and a server in a test case.

            Source https://stackoverflow.com/questions/70446866

            QUESTION

            Best practice for sending to connected clients
            Asked 2021-Dec-19 at 20:16

            I'm trying to design a SwiftNIO server where multiple clients (like 2 or 3) can connect to the server, and when connected, they can all receive information from the server.

            To do this, I create a ServerHandler class which is shared & added to each pipeline of connected clients.

            ...

            ANSWER

            Answered 2021-Dec-19 at 20:16

            Your questions aren't stupid at all!

            1. Yeah, sharing a ChannelHandler probably counts as "not recommended". But not because it doesn't work, it's more that it's unusual and probably not something other NIO programmers would expect. But if you're comfortable with it, it's fine. If you're high-performance enough that you worry about the exact number of allocations per Channel then you may be able to save some by sharing handlers. But I really wouldn't optimise the prematurely.

              If you didn't want to share handlers, then you could use multiple handlers that share a reference to some kind of coordinator object. Don't get me wrong, it's really still the same thing: One shared reference across multiple network connections. The only real difference is that testing that may be a little easier and it would possibly feel more natural to other NIO programmers. (In any case be careful to either make sure that all those Channels are on the same EventLoop or to use external synchronisation (with say a lock, which might not be ideal from a performance point of view).

            2. write just enqueues some data to be written. flush makes SwiftNIO attempt to send all the previously written data. writeAndFlush simply calls write and then flush.

              Why does NIO distinguish between write and flush at all? In high-performance networking applications, the biggest overhead might be the syscall overhead. And to send data over TCP, SwiftNIO has to do a syscall (write, writev, send, ...).

              Any SwiftNIO program will work if you just ignore write and flush and always use writeAndFlush. But, if the network is keeping up, this will cost you one syscall per writeAndFlush call. In many cases however, a library/app that's using SwiftNIO already knows that it wants to enqueue multiple bits of data to be sent over the network. And in that case doing say three writeAndFlush in a row would be wasteful. If would be much better to accumulate the three bits of data and then send them all in one syscall using a "vector write" (e.g. writev syscall). And that's exactly what SwiftNIO would do if you did say write, write, write, flush. So the three writes will all be sent using one writev system call. SwiftNIO will simply get the three pointers to the bits of data and hand them to the kernel which then attempts to send them over the network.

              You can take this even a little further. Let's assume you're a high-performance server and you want to respond to a flood of incoming requests. You'll get your requests from the client over channelRead. If you're now able to reply synchronously, you could just write them responses (which will enqueue) them. And once you get channelReadComplete (which marks the end of a "read burst") you can flush. That would allow you to respond to as many requests as you can get in a single read burst using just one writev syscall. This can be quite an important optimisation in certain scenarios.

            Source https://stackoverflow.com/questions/70414821

            QUESTION

            Swift Vapor project not compiling due to strange errors in swift-nio
            Asked 2021-Oct-15 at 11:31

            I can't get my Swift Vapor project to compile (which was running fine before), because nio produces strange errors all of a sudden:

            Also, swift package update produces this:

            ...

            ANSWER

            Answered 2021-Oct-15 at 11:31

            Besides cleaning & re-building the project, you can try deleting the following files / directories:

            • /.build
            • /.swiftpm
            • /Package.resolved

            Then, run swift package update and try to build the project again.

            Source https://stackoverflow.com/questions/69584059

            QUESTION

            Swift-NIO based proxy reconfigures pipeline on every incoming request
            Asked 2021-Sep-14 at 12:17

            I'm using Swift-NIO to create a Http/2 proxy with TLS, for iOS/tvOS. My proxy startup:

            ...

            ANSWER

            Answered 2021-Sep-14 at 12:17

            This question was handled on the swift Forums https://forums.swift.org/t/swift-nio-based-proxy-reconfigures-pipeline-on-every-incoming-request/52043

            Answer by Lukasa:

            This is expected behaviour. HTTP/2 is multiplexed: this means you can run multiple request/response sequences over the same TCP connection. This manifests in SwiftNIO HTTP/2 in the form of the "stream channel initializer": this is called once per stream creation. The stream channel initializer here is the trailing closure being passed to configureCommonHTTPServerPipeline.

            If you would like to create the handlers only once, you can do that. But now your handlers need to support being involved in multiple concurrent requests and responses.

            Source https://stackoverflow.com/questions/69141348

            QUESTION

            How do I get `Data` objects into Swift-NIO without making copies?
            Asked 2021-Apr-15 at 09:50

            I'm fairly new to Swift and very new to NIO.

            I'm adding Swift code to a large project that needs to up/down load a lot of data (GBs) to AWS. To that end, I've imported the GitHub project Soto, which relies heavily on NIO.

            Most methods that send/receive data do so through ByteBuffer structs. My application already has the data to upload in Foundation Data objects. I'm having trouble figuring out the best way to get these Data objects into NIO.

            In the documentation for NIO's ByteBuffer (2.26.0) it states

            Supported types: A variety of types can be read/written from/to a ByteBuffer. ... Out of the box, ByteBuffer supports for example the following types (non-exhaustive list):

            • String/StaticString
            • Swift’s various (unsigned) integer types
            • Foundation‘s Data
            • [UInt8] and generally any Collection of UInt8

            However, the latest swift-nil package has no ByteBuffer support for Foundation Data objects. Instead, it supports DispatchData objects, which in turn seem to have no interoperability with Data objects.

            What I want to avoid is making a copy of every block of data (100's of MB at a time), just to convert between Data and DispatchData types.

            So...

            Right now my thinking is one of

            • I'm completely lost, and there's a simple solution I haven't found

            • The solution is to create a subclass of DispatchData backed by a Data object

            • Initialize the ByteBuffer structure using a DispatchData created using the no-copy initializer pointing to the raw byte array in the Data object, along with a custom deallocator that simply retains the Data object until the ByteBuffer and DispatchData objects are destroyed.

            I would appreciate any thoughts, experience, or suggestions (particularly if it's option #1).

            ...

            ANSWER

            Answered 2021-Mar-08 at 18:37

            You'll need to import NIOFoundationCompat to get any of NIO's method that work with Foundation data types such as Data (or JSONDecoder/JSONEncoder). NIOFoundationCompat is just another module of the swift-nio package so you won't need another dependency.

            But just to be clear, under the hood, there will always be copies but probably you don't need to worry about them, copies are extremely fast on today's CPUs. If you absolutely want to avoid copies, you'll need to create ByteBuffers straight away. To help you with that, you may want to add where you get your data from that you want to send over the network.

            Source https://stackoverflow.com/questions/66534661

            QUESTION

            TLS CA certificate SSL Pinning using SWIFT-NIO-SSL
            Asked 2020-Apr-05 at 20:52

            I have been trying to use SWIFT-NIO-SSL, to connect to server using the CA certificate and Server certificate.

            After numeral attempts, and trying out different approaches, I could not get a solution. Is there any tutorial or any help in connecting to TLS using ca certificate with swift-nio-ssl would be helpful.

            ...

            ANSWER

            Answered 2020-Apr-05 at 20:52

            I'm not 100% sure if that's what you're asking but are you trying to connect to a server using a custom CA, you probably want the following TLSConfiguraion:

            Source https://stackoverflow.com/questions/61048732

            QUESTION

            Swift-NIO TCP Client auto reconnect
            Asked 2020-Jan-15 at 12:13

            I write a TCP Client in Swift-NIO to connect Netty TCP Server. I want tcp client can auto reconnect when needed.

            ...

            ANSWER

            Answered 2020-Jan-15 at 12:13

            The solution for SwiftNIO will require your handler to attach callbacks to the future returned from connect. These callbacks can close over the repeating task, and so can cancel it when a connection completes. For example:

            Source https://stackoverflow.com/questions/59718703

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install swift-nio

            SwiftNIO primarily uses SwiftPM as its build tool, so we recommend using that as well. If you want to depend on SwiftNIO in your own project, it's as simple as adding a dependencies clause to your Package.swift:.

            Support

            SwiftNIO aims to support all of the platforms where Swift is supported. Currently, it is developed and tested on macOS and Linux, and is known to support the following operating system versions:.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Networking Libraries

            Moya

            by Moya

            diaspora

            by diaspora

            kcptun

            by xtaci

            cilium

            by cilium

            kcp

            by skywind3000

            Try Top Libraries by apple

            swift

            by appleC++

            foundationdb

            by appleC++

            ml-stable-diffusion

            by applePython

            turicreate

            by appleC++

            darwin-xnu

            by appleC