נתוני הבורסה

ברגע שתיצרו חיבורים, תוכלו להתחיל להחליף נתונים. הנתונים שמועברים יכולים להיות בצורת מערך בייט פשוט, כמו הודעת טקסט קצרה, קובץ כמו תמונה או סרטון או שידור, כמו הסטרימינג של האודיו מהמיקרופון של המכשיר.

ניתן לשלוח נתונים באמצעות השיטות הבאות של מופע של מנהל חיבור:

  • send(_:to:)
  • startStream(_:to:)
  • sendResource(at:withName:to:)

כדי לקבל את הנתונים, אתם יכולים להשתמש בשיטות הבאות להאצלה של מנהל החיבור.

Swift

extension Example: ConnectionManagerDelegate {
  func connectionManager(
    _ connectionManager: ConnectionManager, didReceive data: Data,
    withID payloadID: PayloadID, from endpointID: EndpointID) {
    // A simple byte payload has been received. This will always include the full data.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager, didReceive stream: InputStream,
    withID payloadID: PayloadID, from endpointID: EndpointID,
    cancellationToken token: CancellationToken) {
    // We have received a readable stream.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager,
    didStartReceivingResourceWithID payloadID: PayloadID,
    from endpointID: EndpointID, at localURL: URL,
    withName name: String, cancellationToken token: CancellationToken) {
    // We have started receiving a file. We will receive a separate transfer update
    // event when complete.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager,
    didReceiveTransferUpdate update: TransferUpdate,
    from endpointID: EndpointID, forPayload payloadID: PayloadID) {
    // A success, failure, cancelation or progress update.
  }
}