On Apr 21, 4:08 am, My <[EMAIL PROTECTED]> wrote:
> i already search for the same problem. some are helpful but i got this
> weird error.
> im making a tcp connection, have already successfully send my package
> but when i try to read from the socket, it throw exception "Bad
> Socket". im really confuse.
>
> can any body help me about this?
> any help will fully appreciated
>
> this is part of the code :
> Socket socket = new Socket("scs.msg.yahoo.com",5050);
>
>                         DataInputStream dis = new DataInputStream(new
> BufferedInputStream(socket.getInputStream()));
>                         DataOutputStream dos = new DataOutputStream(new
> BufferedOutputStream(socket.getOutputStream()));
>
>                         dos.write(header);
>
>                         dos.writeChar(len); // write 2 byte of length
>                         dos.writeChar(service); // write 2 byte
>                         dos.writeInt(status); // write 4 byte of status
>                         dos.writeInt(sesionId); // write 4 byte of session ID
>                         dos.write(bs.toByteArray()); // write body

//next line is the error code
>                         dos.close();
>
>                         Log.v(this.TAG,dis.readUTF()); // this part throw 
> exception.
>                         fout.close();
>                 } catch (IOException e) {
>                         // TODO Auto-generated catch block
>                         Log.e(this.TAG,e.getMessage());
>                         e.printStackTrace();
>                 }

woops i found the mistake. its in line "dos.close()" . i think is
kinda close the socket connection. so in order to flush the buffer
dont close the InputStream  but use dos.flush(). this method will
flush the buffered data and still open the connection. hope this help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to