Andre DeMattia
Andre DeMattia

Reputation: 630

WP 8 NFC File Transfer

I'm looking for an example on how to transfer a large file via NFC (Bluetooth) from one Windows phone 8 to another.

I think I need to make the connection via NFC then do the transfer over Bluetooth but I can't find any examples.

Upvotes: 0

Views: 1402

Answers (2)

kindasimple
kindasimple

Reputation: 2427

There was a networking talk at the Build conference that you may get some ideas from. It focuses on sockets and NFC. Windows Phone 8: Networking, Bluetooth, and NFC Proximity for Developers. See the sample project for code. There is also a sample on Devcenter for StreamSocket.

Upvotes: 0

JustinAngel
JustinAngel

Reputation: 16102

NFC isn't a good format to transfer files. It's slow, it has low bandwidth and it's generally unreliable for long periods of time. NFC is really good to start a tap-and-share session that escalates to a bluetooth or WiFi file transfer. Lucky us, that's what PeerFinder does best.

In essence first you'll need to find a new peer via NFC. You can do that either by using TriggeredConnectionStateChanged event or subscribe to an app-to-app NFC message between two devices.

Next, you should open a StreamSocket between those two peers. At this point, communication is unstructured by default. Meaning, you send and receive a stream of bytes and you as the developer need to make sense of them. If you want to transfer files, go for it, but you'll have to structure the Bluetooth StreamSocket to expect those. Such a structure might look like |1 byte to signal version number|1 byte to signal file transfer start|4 bytes to transfer an int32 of file size in bytes|file contents in bytes in specified length|4 bytes for file contents MD5/SHA1 hash to verify the file's contents|. It's really up to you what the protocol would look like, but remember that you have to send and receive bytes.

Nokia has an end-to-end sample of initiating an NFC tap-and-share, opening a StreamSocket and transfering structured messages over that socket. It's not files, but it'll show you how to use NFC, escalate to WiFi/Bluetooth and use a real-world versioned structured message format. Check out Nokia's NFC Talk project here and here for the interesting part.

Upvotes: 3

Related Questions