BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-23-2009, 02:14 PM   #1 (permalink)
New Member
 
Join Date: Feb 2009
Location: Marshalltown, IA USA
Model: 8310
PIN: N/A
Carrier: AT&T
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default DataInputStream read() does not receive

Please Login to Remove!

So I'm writing an application that uses the network. For the "server" device I am connecting to the protocol is a request response so I created a TcpClient class that connects to a given IP/Port and then has a send method that sends the request and receives the response which is then returned. I am currently running this only on the JDE w/ the simulator as I don't have the server device on the internet yet.

The problem I'm having is the request is sent (I see it in Wireshark doing a network capture) and a response is issued back from the server (again, see it on wireshark). I issue a DataInputStream.read(byte[]) and my application locks up and I do not receive any data. Here is the code for this function.

Code:
  MyTcpClient(String client, int port)
  {
    String args = new String("socket://" + client + ":" + Integer.toString(port) + ";deviceside=true");
        
    try
    {
      socket = (SocketConnection)Connector.open(args, Connector.READ_WRITE, true);
      
    }
    catch (IOException e)
    {
      System.out.println(e);
    }
    
    is = null;
    os = null;
  }

  public boolean connect()
  {
    boolean ret = false;
    try
    {
      is = socket.openDataInputStream();
      os = socket.openDataOutputStream();
      ret = true;
    }
    catch (IOException e)
    {
      System.out.println(e);
    }
    
    return ret;
  }

  public byte[] send(byte[] data, int size)
  {
    byte ret[] = new byte[1024];
    
    if (is != null && os != null && socket != null)
    {
      try
      {          
        os.write(data, 0, size);
        //os.flush();
        int len = 0;
        while (-1 != (len = is.read(ret)))
        {
          System.out.println("Byte's received: " + String.valueOf(len));
        }
        System.out.println("Howdy");
      }
      catch (IOException e)
      {
        System.out.println(e);
      }
    }
    
    return ret;
  }
The response coming back is around 200 bytes so I should be able to get it in one receive and pass it back. The code stops on the "while( -1 !=...." line. Any ideas?
Offline  
Old 06-30-2009, 03:43 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2009
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 33
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im facing same problem...how it can b resolved?
Offline  
Closed Thread


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

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





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.