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): LiteP2PgetInstance()
Returns the singleton instance. Must be called after initialize.
getInstance(): LiteP2PInstance methods
connect(callback)
Connects to the network and starts discovery. Use the callback for success/error.
connect(callback: (result: ConnectionResult) -> Unit): voiddisconnect()
Disconnects and stops all active sessions.
disconnect(): voidisConnected()
Returns whether the engine is connected.
isConnected(): BooleansendMessage(peerId, data, callback)
Sends a message to a peer and reports a SendResult.
sendMessage(peerId: String, data: ByteArray, callback: (SendResult) -> Unit): voidonMessage(handler)
Registers a handler for inbound Message events.
onMessage(handler: (Message) -> Unit): voidsendFile(peerId, file, options)
Starts a file transfer and returns a FileTransfer. Configure behavior with TransferOptions.
sendFile(peerId: String, file: File, options: TransferOptions): FileTransferExample
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).