Class NWTCPConnection

  • All Implemented Interfaces:
    NSObject

    public class NWTCPConnection
    extends NSObject
    [@interface] NWTCPConnection Establish TCP connections to an endpoint, and send and receive data on the TCP connection.
    • Constructor Detail

      • NWTCPConnection

        protected NWTCPConnection​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • cancel

        public void cancel()
        cancel: Cancel the connection. This will clean up the resources associated with this object and transition this object to NWTCPConnectionStateCancelled state.
      • connectedPath

        public NWPath connectedPath()
        [@property] connectedPath The network path over which the connection was established. The caller can query additional properties from the NWPath object for more information. Note that this contains a snapshot of information at the time of connection establishment for this connection only. As a result, some underlying properties might change in time and might not reflect the path for other connections that might be established at different times.
      • endpoint

        public NWEndpoint endpoint()
        [@property] endpoint The destination endpoint with which this connection was created.
      • error

        public NSError error()
        [@property] error The connection-wide error property indicates any fatal error that occurred while processing the connection or performing data reading or writing.
      • hasBetterPath

        public boolean hasBetterPath()
        [@property] hasBetterPath YES if the system determines there is a better path the destination can be reached if the caller creates a new connection using the same endpoint and parameters. This can be done using the convenience upgrade initializer method. Use KVO to watch this property to get updates.
      • initWithUpgradeForConnection

        public NWTCPConnection initWithUpgradeForConnection​(NWTCPConnection connection)
        initWithUpgradeForConnection: This convenience initializer can be used to create a new connection that would only be connected if there exists a better path (as determined by the system) to the destination endpoint of the original connection. It will be initialized using the same destination endpoint and set of parameters from the original connection. If the original connection becomes disconnected or cancelled, the new "upgrade" connection would automatically be considered better. The caller should create an NWTCPConnection and watch for the hasBetterPath property. When this property is YES, the caller should attempt to create a new upgrade connection, with the goal to start transferring data on the new better path as soon as possible to reduce power and potentially monetary cost. When the new upgrade connection becomes connected and when the caller wraps up the previous caller session on the original connection, the caller can start using the new upgrade connection and tear down the original one.
        Parameters:
        connection - The original connection from which the caller will upgrade
        Returns:
        An initialized NWTCPConnection
      • isViable

        public boolean isViable()
        [@property] viable YES if the connection can read and write data, NO otherwise. Use KVO to watch this property.
      • localAddress

        public NWEndpoint localAddress()
        [@property] localAddress The IP address endpoint from which the connection was connected.
      • readLengthCompletionHandler

        public void readLengthCompletionHandler​(long length,
                                                NWTCPConnection.Block_readLengthCompletionHandler completion)
        readLength:completionHandler: Read "length" number of bytes. See readMinimumLength:maximumLength:completionHandler: for a complete discussion of the callback behavior.
        Parameters:
        length - The exact number of bytes the application wants to read
        completion - The completion handler to be invoked when there is data to read or an error occurred
      • readMinimumLengthMaximumLengthCompletionHandler

        public void readMinimumLengthMaximumLengthCompletionHandler​(long minimum,
                                                                    long maximum,
                                                                    NWTCPConnection.Block_readMinimumLengthMaximumLengthCompletionHandler completion)
        readMinimumLength:maximumLength:completionHandler: Read the requested range of bytes. The completion handler will be invoked when: - Exactly "length" number of bytes have been read. 'data' will be non-nil. - Fewer than "length" number of bytes, including 0 bytes, have been read, and the connection's read side has been closed. 'data' might be nil, depending on whether there was any data to be read when the connection's read side was closed. - Some fatal error has occurred, and 'data' will be nil. To know when to schedule a read again, check for the condition whether an error has occurred. For better performance, the caller should pick the effective minimum and maximum lengths. For example, if the caller absolutely needs a specific number of bytes before it can make any progress, use that value as the minimum. The maximum bytes can be the upperbound that the caller wants to read. Typically, the minimum length can be the caller protocol fixed-size header and the maximum length can be the maximum size of the payload or the size of the current read buffer.
        Parameters:
        minimum - The minimum number of bytes the caller wants to read
        maximum - The maximum number of bytes the caller wants to read
        completion - The completion handler to be invoked when there is data to read or an error occurred
      • remoteAddress

        public NWEndpoint remoteAddress()
        [@property] remoteAddress The IP address endpoint to which the connection was connected.
      • state

        public long state()
        [@property] state The status of the connection. Use KVO to watch this property to get updates.
      • txtRecord

        public NSData txtRecord()
        [@property] txtRecord When the connection is connected to a Bonjour service endpoint, the TXT record associated with the Bonjour service is available via this property. Beware that the value comes from the network. Care must be taken when parsing this potentially malicious value.
      • writeCompletionHandler

        public void writeCompletionHandler​(NSData data,
                                           NWTCPConnection.Block_writeCompletionHandler completion)
        write:completionHandler: Write the given data object content. Callers should wait until the completionHandler is executed before issuing another write.
        Parameters:
        data - The data object whose content will be written
        completion - The completion handler to be invoked when the data content has been written or an error has occurred. If the error is nil, the write succeeded and the caller can write more data.
      • writeClose

        public void writeClose()
        writeClose: Close this connection's write side such that further write requests won't succeed. Note that this has the effect of closing the read side of the peer connection. When the connection's read side and write side are closed, the connection is considered disconnected and will transition to the appropriate state.