Even with bluetooth, you can create a client server application .. there is a BluetoothSocket read here http://developer.android.com/reference/android/bluetooth/BluetoothSocket.html
Now, let's say you have two devices:
and suppose device A sending data to device B, you did not say that device B also sends data to device A, so I’ll just describe the first scenario when A sends B.
So, in this case, since all the data is stored in device A, and you want to send it to device B, it would be wiser to create device A as a Bluetooth server and device B as a BluetoothClient that listens to the server.
But .. If you want both devices to exchange data, you can make one of them as a server and 2 streams are created for each of them:
- Subject sending data
- a stream that listens for data
so that both of them can exchange data.
Another thing. If you have ever programmed a regular client server, you notice the accept() method, which locks until there is a client connected to the server. Same thing with the Bluetooth client-client application.
Summarize:
One device will act as a server - so you will need to write a server project and install it on the first device
The second device will act as a client - so you will need to write a client project and install it on the second device
Remember to add the Bluetooth permission to the manifest file for both projects.
Both projects need the same UUID as your question. In simple words, both parties need a UUID so that each of them knows who they are talking to. I think this is more like a port on a regular client server. I read somewhere that it is used for RFC communication .. as you probably know, there are some protocols for Bluetooth, such as RFC, SDP, etc.
EDIT: Most phones have a pairing process when you want to send data via Bluethooth. so if you do not want to use the client-server version, I think you can do the following:
- Your application will search for devices to connect. (pairing process)
- After pairing, you connect to another device and simply send data
EDIT 2: Do you want to send data from A to B to the right? I will explain more clearly.
You are right when you say that the client needs to know who the server is, and you need to insert the port and the IP address of the server is correct and works this way.
Now take a look.
The server listens for a connection with clients when a connection has been established.
- Customer requests data
The server processes the client request and sends it the corresponding data.
Thus, any data, such as: Files, databases should be stored on the server side.
Now, in your case, the files you want to send are in device A, and not in device B. Therefore, if device A is a server, it will listen for connections .. when device B connects to the server (device A), communication begins. Device B can request files from device A .. In addition, since device A is a server, it can even broadcast a message .. means to send the same message to all clients associated with it.
But what you want to do is send the file even if device b did not request it, right? I don’t understand if you want device B to also send the file to device A, so we’ll split it into
in the script:
just send device A to B: In this case, since the files are in device A, it means that device A has data, device A is the server, and device B is the client. Therefore, when the connection is established, you can send from A to B.
Both devices communicate: In this case, both devices must listen to each other, but only one of them must act as a server and the other as a client. means that you need to install serverApp one of them and clientApp on the other. But each of them can send and listen to others. therefore, for each of them you need to create a stream that processes the transmitted data and another stream that processes the received data.