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?