rainwhisper
Newbie level 3
Urgent PLZ help
Hi all,
hope all fine and every thing go good with you.
i went to build application that need communication between server and mobile. the mobile send data to the server successfully but the mobile doesn't receive data from server although i open data input stream. i build another client using C# to be sure that the problem from the server or mobile and i found that the server is ok. ..... really i don't know what is the problem can any body help me
and this is my connection code
public void connection() throws IOException
{
HttpConnection conn = null;
String url = "http://www.myserver.com/test.txt";
DataInputStream dis = null;
DataOutputStream dos = null;
try
{
conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
conn.setRequestMethod(conn.POST);
conn.setRequestProperty("Content-Type", "//text plain");
conn.setRequestProperty("Content-Language", "en-US");
String username = loginScreen.getUsername();
String password = loginScreen.getPassword();
String send = "username : " + username + "password : " + password
dos = conn.openDataOutputStream();
dos.write(send.getBytes());
dos.flush();
int res_code = conn.getResponseCode();
if(res_code != HttpConnection.HTTP_OK)
{
throw new IOException ("fail to connect to the server");
}
dis = conn.openDataInputStream();
int length = (int) conn.getLength();
if (length > 0)
{
int actual = 0;
int bytes_read = 0;
byte[] data = new byte [length];
while ((bytes_read != length)&& (actual != -1))
{
actual = dis.read(data, bytes_read, length - bytes_read);
bytes_read += actual;
}
}
} // end of try
catch (IOException error)
{
System.out.println("caught IO exception" );;
}
finally
{
if (dis != null)
dis.close();
if (dos != null)
dos.close();
if (conn != null)
conn.close();
}
}
thanks in advance,
Hi all,
hope all fine and every thing go good with you.
i went to build application that need communication between server and mobile. the mobile send data to the server successfully but the mobile doesn't receive data from server although i open data input stream. i build another client using C# to be sure that the problem from the server or mobile and i found that the server is ok. ..... really i don't know what is the problem can any body help me
and this is my connection code
public void connection() throws IOException
{
HttpConnection conn = null;
String url = "http://www.myserver.com/test.txt";
DataInputStream dis = null;
DataOutputStream dos = null;
try
{
conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
conn.setRequestMethod(conn.POST);
conn.setRequestProperty("Content-Type", "//text plain");
conn.setRequestProperty("Content-Language", "en-US");
String username = loginScreen.getUsername();
String password = loginScreen.getPassword();
String send = "username : " + username + "password : " + password
dos = conn.openDataOutputStream();
dos.write(send.getBytes());
dos.flush();
int res_code = conn.getResponseCode();
if(res_code != HttpConnection.HTTP_OK)
{
throw new IOException ("fail to connect to the server");
}
dis = conn.openDataInputStream();
int length = (int) conn.getLength();
if (length > 0)
{
int actual = 0;
int bytes_read = 0;
byte[] data = new byte [length];
while ((bytes_read != length)&& (actual != -1))
{
actual = dis.read(data, bytes_read, length - bytes_read);
bytes_read += actual;
}
}
} // end of try
catch (IOException error)
{
System.out.println("caught IO exception" );;
}
finally
{
if (dis != null)
dis.close();
if (dos != null)
dos.close();
if (conn != null)
conn.close();
}
}
thanks in advance,