You have not posted quite enough information for us to be sure we can
help you. Can I assume, for example, that your variable 'Socket' is a
BluetoothSocket? Why have you not followed any of the coding standards
for the name, then? The Sun standards, and many others, all call for
class names to start with capital letters, but object and primitive
variables names to start with lower case. If you want people to be
able to help you, make our job easier: follow the standards so that we
can read the code without more effort than we feel helping you is
worth.

For that matter, how do we know you did not implement it as
BluetoothServerSocket? This too, is an example of insufficient
information.

For my final example of insufficient information, what did you do in
between the "first time" and the second? Did you call run() again? How
do you determine when it is time to call run() again? You will need to
do this to talk to the remote device again, since you closed not only
the BufferedOutputStream, but even the BluetoothSocket (assuming that
is what 'Socket' really is).

BTW: how did you decide that you have to close the socket itself
rather than just the output stream? Have you considered leaving the
socket connected? Look at
http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.html
and see how it does it.

On Jun 27, 2:48 am, mark2011 <[email protected]> wrote:
> Dear All :
>
>    I'm a new to Android.
>
>    I try to code a client API to allow the user to input some data in
> an android 2.1 to send out through the bluetooth. The hyperterminal
> can displays the received data in a Windows pc in the first time. But
> When I input data the second time from the Android, the pc can't
> receive the data any more.
>
> My code is the below :
> public void run() {
>             adapter.cancelDiscovery();
>
>                 try {
>                         Socket.connect();
>                         BufferedOutputStream bout = new
> BufferedOutputStream(Socket.getOutputStream());
>                     bout.write(str1.getBytes());
>
>                     bout.flush();
>                     bout.close();
>                     } catch (IOException connectException) {
>                     Log.i("BT Client", "not connect");
>                     try {
>                         Socket.close();
>                     } catch (IOException closeException) { }
>                     return;
>                 }
>             }
>
> Can anyone help me?
>
> Thanks in advanced.
>
> BR,
> Mark

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to