The CFSocketCreate method or constructor is missing. How to create a CFSocket using Swift?

Any method call to instantiate a CFSocket seems to be missing from a CoreFoundation import

import CoreFoundation

var socket:CFSocket = CFSocket()

The help documentation does not display anything when only the arrow is selected:

Creating Sockets

4 Objective-C symbols hidden

How can I create a CFSocket instance under Swift?

+4
source share
2 answers

I had the same problem. This is a CF structure, not an object, so you do not have a constructor. You can use CFSocketCreate.

Some people think so:

  let socket : CFSocket = CFSocketCreate(_ allocator: CFAllocator!,
              _ protocolFamily: Int32,
              _ socketType: Int32,
              _ `protocol`: Int32,
              _ callBackTypes: CFOptionFlags,
              _ callout: CFSocketCallBack,
              _ context: UnsafePointer<CFSocketContext>)

Reference

0
source

replace the callout with closing as shown below:

let socket = CFSocketCreate(kCFAllocatorDefault,
                          PF_INET, 
                          SOCK_STREAM, 
                          IPPROTO_TCP, 
                          2,
                          { (socket,_,_,_,_) in },
                          nil)
0
source

Source: https://habr.com/ru/post/1545023/


All Articles