Reputation: 4270
I can successfully connect through Bluetooth my Nexus One Android Phone to another Bluetooth Android Phone. I can use the input and output streams for connection and write my requests and read their responses . My application uses real time data for processing. I was wondering is there any way to open two input/output streams on different sockets (sort of like dedicated sockets) for communication? And if yes how could i accomplish that ? Any pointers would be helpful ...
mmSocket.connect();
public void connect () Since: API Level 5 Attempt to connect to a remote device.
This method will block until a connection is made or the connection fails. If this method returns without an exception then this socket is now connected.
Creating new connections to remote Bluetooth devices should not be attempted while device discovery is in progress. Device discovery is a heavyweight procedure on the Bluetooth adapter and will significantly slow a device connection. Use cancelDiscovery() to cancel an ongoing discovery. Discovery is not managed by the Activity, but is run as a system service, so an application should always call cancelDiscovery() even if it did not directly request a discovery, just to be sure.
Now my question is : How can i connect using two sockets ... because the function above uses a socket to connect ... And after a connection it disconnects any other attempt by another socket ????
Upvotes: 0
Views: 3168
Reputation: 852
It is of course possible, but I am guessing you use blocking calls for the sockets, so you will need more than one thread to do useful work in real time. This also means you need a bit of synchronization between threads if they are to communicate.
Your'e question is frankly a bit vague, so I don't think you will get any good answers unless you qualify it a bit: what exactly do you want to do? Why do you need more than one socket? What is the second socket for?
Upvotes: 2