<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1504">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #929292}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #0433ff}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #b4261a}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #3495af}
span.s5 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3495af}
</style>
</head>
<body>
<p class="p1">Hi all,</p>
<p class="p2"><br></p>
<p class="p1">I've started working on an implementation of (NS)NetService (https://github.com/Bouke/NetService), in pure Swift. My goal is to stay close to the version in Cocoa. While I've got an intial working version, I've hit a snag. When publishing a NetService, you can also listen for connections for that service:</p>
<p class="p2"><br></p>
<p class="p3"><span class="s1">let</span><span class="s2"> ns = NetService(domain: </span><span class="s3">"local."</span><span class="s2">, type: </span><span class="s3">"_airplay._tcp."</span><span class="s2">, name: </span><span class="s3">"demo"</span><span class="s2">, port: 7000)</span></p>
<p class="p3"><span class="s2">ns.publish(options: [.listenForConnections])</span></p>
<p class="p2"><br></p>
<p class="p1">The NetService's delegate has<span class="Apple-converted-space"> </span>a method for accepting connections:</p>
<p class="p2"><br></p>
<p class="p3"><span class="s2"><span class="Apple-converted-space"> </span></span><span class="s1">func</span><span class="s2"> netService(</span><span class="s1">_</span><span class="s2"> sender: </span><span class="s4">NetService</span><span class="s2">,</span></p>
<p class="p3"><span class="s2"><span class="Apple-converted-space"> </span>didAcceptConnectionWith inputStream: </span><span class="s4">InputStream</span><span class="s2">,</span></p>
<p class="p3"><span class="s2"><span class="Apple-converted-space"> </span>outputStream: </span><span class="s4">OutputStream</span><span class="s2">)</span></p>
<p class="p2"><br></p>
<p class="p1">I've setup a CFSocket for listening and inside the accept callback it creates a CFReadStream and a CFWriteStream using <span class="s5">CFStreamCreatePairWithSocket</span>. The problem is that CFNetwork is not available on Linux and probably will never be. So <span class="s5">CFStreamCreatePairWithSocket</span> is not available.</p>
<p class="p2"><br></p>
<p class="p1">So the question is; how to create <span class="s5">InputStream</span> and <span class="s5">OutputStream</span> inside the accept callback without CFNetwork?</p>
<p class="p2"><br></p>
<p class="p4">--<span class="Apple-converted-space"> </span></p>
<p class="p4">-Bouke</p>
</body>
</html>