LiteP2P

The main entry point for the LiteP2P SDK. Handles initialization, connectivity, peer discovery, messaging, and file transfer.

Static methods

initialize(context, config)

Initializes the engine with the provided PeerConfig.

initialize(context: Context, config: PeerConfig): LiteP2P

getInstance()

Returns the singleton instance. Must be called after initialize.

getInstance(): LiteP2P

Instance methods

connect(callback)

Connects to the network and starts discovery. Use the callback for success/error.

connect(callback: (result: ConnectionResult) -> Unit): void

disconnect()

Disconnects and stops all active sessions.

disconnect(): void

isConnected()

Returns whether the engine is connected.

isConnected(): Boolean

sendMessage(peerId, data, callback)

Sends a message to a peer and reports a SendResult.

sendMessage(peerId: String, data: ByteArray, callback: (SendResult) -> Unit): void

onMessage(handler)

Registers a handler for inbound Message events.

onMessage(handler: (Message) -> Unit): void

sendFile(peerId, file, options)

Starts a file transfer and returns a FileTransfer. Configure behavior with TransferOptions.

sendFile(peerId: String, file: File, options: TransferOptions): FileTransfer

Example

val config = PeerConfig.Builder()
    .setAppId("your-app-id")
    .build()

LiteP2P.initialize(context, config)

val p2p = LiteP2P.getInstance()
p2p.connect { /* ... */ }

Notes

  • Keep a single initialized instance per process.
  • On mobile, align connection lifecycle with foreground/background strategy (see Android docs).