Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old March 1st, 2011, 09:21 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default android socket read/write client help!

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:
try {

        FTPSocket = new Socket("209.85.149.105",80);//google.com
    } catch (Exception e) {

        return false;
    }


    try {
            buf_in = new BufferedReader(new InputStreamReader(FTPSocket.getInputStream()));

            buf_out = new BufferedWriter(new OutputStreamWriter(FTPSocket.getOutputStream()));
        } catch (Exception e) {

            return false;
        }

    try{

        buf_out.write(send,0,send.length());//send is string with "Hi"
    } catch (Exception e) {

        return false;
    }

    try{

        buf_in.read(read,0,1000);//read variable is a char[]


    }catch (Exception e) {

        return false;
    }

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!

Advertisements
wenn32 is offline  
Reply With Quote
sponsored links
Old March 2nd, 2011, 12:35 AM   #2 (permalink)
Member
 
Join Date: Apr 2010
Location: Netherlands
Posts: 142
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 1
Thanked 23 Times in 23 Posts
Default

You can only read as much as the length of your char[]
id0001 is offline  
Reply With Quote
Old March 2nd, 2011, 06:38 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Feb 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

it throws an exception in this part

Code:
try{
   buf_in.read(read,0,1000);//read variable is a char[]
}catch (Exception e) {
   return false;
}
i checked whether it was indexoutofbounds or IO exception but it was neither of these.what could be the problem in this TCP model
wenn32 is offline  
Reply With Quote
Old March 3rd, 2011, 12:43 AM   #4 (permalink)
Member
 
Join Date: Apr 2010
Location: Netherlands
Posts: 142
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 1
Thanked 23 Times in 23 Posts
Default

what's the size of the 'read' variable?
Also what kind of exception do you get?
id0001 is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:27 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.