1. Check out our companion app, Forums for Android! Download from Google Play

android socket read/write client help!

Discussion in 'Application Development' started by wenn32, Mar 1, 2011.

  1. wenn32

    wenn32 New Member
    Thread Starter
    5

    Feb 18, 2011
    2
    0
    5
    hello guys i have been trying to read and write data to socket buffer i even looked into example but went in vain
    here is my code (only client)


    Code (Text):
    1.  
    2. try {
    3.  
    4.         FTPSocket = new Socket("209.85.149.105",80);//google.com
    5.     } catch (Exception e) {
    6.  
    7.         return false;
    8.     }
    9.  
    10.  
    11.     try {
    12.             buf_in = new BufferedReader(new InputStreamReader(FTPSocket.getInputStream()));
    13.  
    14.             buf_out = new BufferedWriter(new OutputStreamWriter(FTPSocket.getOutputStream()));
    15.         } catch (Exception e) {
    16.  
    17.             return false;
    18.         }
    19.  
    20.     try{
    21.  
    22.         buf_out.write(send,0,send.length());//send is string with "Hi"
    23.     } catch (Exception e) {
    24.  
    25.         return false;
    26.     }
    27.  
    28.     try{
    29.  
    30.         buf_in.read(read,0,1000);//read variable is a char[]
    31.  
    32.  
    33.     }catch (Exception e) {
    34.  
    35.         return false;
    36.     }
    37.  

    i tried to change
    buf_in.read(read,0,1000); to buf_in.read(read,0,5000);
    i getting an exception at the buf_in.read().please help me i am stuck


    Thanks!
     

    Advertisement

  2. id0001

    id0001 Well-Known Member
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
    You can only read as much as the length of your char[]
     
  3. wenn32

    wenn32 New Member
    Thread Starter
    5

    Feb 18, 2011
    2
    0
    5
    it throws an exception in this part

    Code (Text):
    1.  
    2. try{
    3.    buf_in.read(read,0,1000);//read variable is a char[]
    4. }catch (Exception e) {
    5.    return false;
    6. }
    7.  
    i checked whether it was indexoutofbounds or IO exception but it was neither of these.what could be the problem in this TCP model
     
  4. id0001

    id0001 Well-Known Member
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
    what's the size of the 'read' variable?
    Also what kind of exception do you get?
     

Share This Page

Loading...