public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); CFStream.CreatePairWithSocketToHost(ipEndPoint, out readStream, out writeStream); inputStream = ObjCRuntime.Runtime.GetNSObject <NSInputStream>(readStream.Handle); outputStream = ObjCRuntime.Runtime.GetNSObject <NSOutputStream>(writeStream.Handle); inputStream.ServiceType = NSStreamServiceType.VoIP; outputStream.ServiceType = NSStreamServiceType.VoIP; // // or ? inputStream[NSStream.NetworkServiceType] = NSStream.NetworkServiceTypeVoIP; outputStream[NSStream.NetworkServiceType] = NSStream.NetworkServiceTypeVoIP; inputStream.OnEvent += HandleInputEvent; outputStream.OnEvent += HandleOutputEvent; outputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // TODO check inputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // TODO check // readStream.EnableEvents(CFRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // writeStream.EnableEvents(CFRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); outputStream.Open(); inputStream.Open(); // UIApplication.SharedApplication.SetKeepAliveTimeout(1, null); // Not supported any more. return(true); }
public unsafe void Write() { using (var s = (NSOutputStream)NSOutputStream.OutputStreamToMemory()) { s.Open(); s.Write(new byte[] { 1, 2, 3 }, 3); using (var obj = s [NSStream.DataWrittenToMemoryStreamKey] as NSData) { Assert.IsNotNull(obj, "a"); Assert.AreEqual(1, Marshal.ReadByte(obj.Bytes, 0), "a[0]"); Assert.AreEqual(2, Marshal.ReadByte(obj.Bytes, 1), "a[1]"); Assert.AreEqual(3, Marshal.ReadByte(obj.Bytes, 2), "a[2]"); } } using (var s = new NSOutputStream()) { s.Open(); s.Write(new byte[] { 1, 2, 3 }); using (var obj = s [NSStream.DataWrittenToMemoryStreamKey] as NSData) { Assert.IsNotNull(obj, "a"); Assert.AreEqual(1, Marshal.ReadByte(obj.Bytes, 0), "b[0]"); Assert.AreEqual(2, Marshal.ReadByte(obj.Bytes, 1), "b[1]"); Assert.AreEqual(3, Marshal.ReadByte(obj.Bytes, 2), "b[2]"); } } using (var s = (NSOutputStream)NSOutputStream.OutputStreamToMemory()) { s.Open(); s.Write(new byte[] { 1, 2, 3 }, 2, 1); using (var obj = s [NSStream.DataWrittenToMemoryStreamKey] as NSData) { Assert.IsNotNull(obj, "a"); Assert.AreEqual(3, Marshal.ReadByte(obj.Bytes, 0), "c[0]"); } } }
internal ExternalAccessoryNetworkStream(EASession session) { _delegate = new EAStreamDelegate(this); _inputStream = session.InputStream; _outputStream = session.OutputStream; _inputStream.Open(); _outputStream.Delegate = _delegate; _outputStream.Schedule(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); _outputStream.Open(); }
public void Open() { _outputStream?.Open(); }
IObservable<Unit> SaveFullResolutionImageToFile (FileRequest request) { return Observable.Create<Unit> (o => { var description = request.DescriptionAs<AssetDescription> (); var disp = new CancellationDisposable (); var token = disp.Token; GetAsset (description, token).ContinueWith (t => { using (File.Create (request.Filename)) using (var asset = t.Result) using (var representation = asset.DefaultRepresentation) using (var stream = new NSOutputStream (request.Filename, true)) { stream.Open (); long offset = 0; uint bytesRead = 0; NSError err; // A large enough buffer that shouldn't cause memory warnings byte [] buffer = new byte [131072]; GCHandle handle = GCHandle.Alloc (buffer, GCHandleType.Pinned); IntPtr pointer = handle.AddrOfPinnedObject (); unsafe { while (offset < representation.Size && stream.HasSpaceAvailable ()) { bytesRead = representation.GetBytes (pointer, offset, (uint)buffer.Length, out err); stream.Write (buffer, bytesRead); offset += bytesRead; } } stream.Close (); handle.Free (); } o.OnCompleted (); }, token).RouteExceptions (o); return disp; }); }