Sockets receiving null (Android)
Posted
by Henrik
on Stack Overflow
See other posts from Stack Overflow
or by Henrik
Published on 2010-05-15T15:26:07Z
Indexed on
2010/05/15
15:34 UTC
Read the original article
Hit count: 327
I have a android app that is communicating with a server (written in java). Between these two parts I have established a Socket connection and want to send data. The problem I am having is that sometimes, for some users, the information that reaches the server is null.
This works (for all phones, all users):
Server:
int a = Integer.parseInt(in.readLine());
int b = Integer.parseInt(in.readLine());
int c = Integer.parseInt(in.readLine());
int d = Integer.parseInt(in.readLine());
String checksum = in.readLine();
String model = in.readLine();
String device = in.readLine();
String name = in.readLine();
Client:
out.println(a);
out.println(b);
out.println(c);
out.println(d);
out.println(hash);
out.println(Build.MODEL);
out.println(Build.DEVICE);
String name = fixName();
out.print(name);
out.flush();
This does not work (for some users):
Server:
int a = Integer.parseInt(in.readLine());
String checksum = in.readLine();
String model = in.readLine();
String device = in.readLine();
String name = in.readLine();
String msg = in.readLine();
int version = -1;
String test = "hej";
try{
test = in.readLine();
version = Integer.parseInt(test);
}catch(Exception e){
e.printStackTrace();
}
Client:
out.println(a);
out.println(hash);
out.println(Build.MODEL);
out.println(Build.DEVICE);
String name = fixName();
if(name == null) name = "John Doe";
out.println(name);
String msg = fixMsg();
if(msg == null) name = "nada";
out.println(msg);
out.println(curversion);
out.flush();
Sometimes, in the second case, the name, msg, and version (the string test) are null at the server side. The catch is triggered because test is null.
curversion,a are ints, the rest are strings.
Any ideas?
© Stack Overflow or respective owner