SwiftDSSocket
public class SwiftDSSocket: NSObject
SwiftDSSocket class definition
-
store user data that can be used for context
Declaration
Swift
public var userData: Any? -
debug option (might be deprecated in future)
Declaration
Swift
public static var debugMode = false -
this defines all kinds of error in SwiftDSSocket
See moreDeclaration
Swift
public class SocketError: NSObject, Error -
Declaration
Swift
public enum SocketType -
create a new SwiftDSSocket instance by specifying delegate, delegate queue and socket type
Declaration
Swift
public init(delegate: SwiftDSSocketDelegate?, delegateQueue: DispatchQueue?, type: SocketType)Parameters
delegatespecify delegate target (normally self)
delegateQueuespecify the GCD dispatch queue for delegate methods
typesocket type: tcp or kernel
-
let SwiftDSSocket connect to IPv4 in priority
Declaration
Swift
public func preferIPv4() -
listen on a specified port for both IPv4/IPv6
Throws
throws a SocketErrorDeclaration
Swift
public func accept(onPort port: UInt16) throwsParameters
portport number in UInt16
-
connect to a host using address:port
Throws
throws a SocketErrorDeclaration
Swift
public func connect(toHost host: String, port: UInt16) throwsParameters
hosthost address could be IP(v4/v6) or domain name in
Stringportport number in UInt16
-
Undocumented
Declaration
Swift
public class SwiftDSSocket: NSObject -
write data to socket
Declaration
Swift
public func write(data: Data, tag: Int)Parameters
datadata ready to send to socket in
Datatypetaga tag to mark this write operation
-
read data from socket without given data length
Declaration
Swift
public func readData(tag: Int)Parameters
taga tag to mark this read operation
-
read specified length of data from socket the callback will be invoked right after read specified amount of data
Declaration
Swift
public func readData(toLength: UInt, tag: Int)Parameters
toLengthlength of data to read
taga tag to mark this read operation
-
read specified length of data into buffer that starts from offset
users should make sure that buffer will not overflow
Declaration
Swift
public func readData(toLength: UInt, buffer: UnsafeMutablePointer<UInt8>, offset: Int, tag: Int)Parameters
toLengthlength of data to read
bufferbuffer given by user
offsetoffset of buffer
taga tag to mark this read operation
-
disconnect socket after all read opreations queued up and prevents new read operations
Declaration
Swift
public func disconnectAfterReading() -
disconnect socket after all write opreations queued up and prevents new write operations
Declaration
Swift
public func disconnectAfterWriting() -
disconnect socket after all opreations queued up and prevents new operations
Declaration
Swift
public func disconnectAfterReadingAndWriting() -
simply disconnect socket and discards all opreations queued up
Declaration
Swift
public func disconnect()
SwiftDSSocket Class Reference