Kindly, I am having a java server and an android mobile client, the server gets an object from database (revokedUser) and sends it to the android client.
However the client receives the object by Object input stream but blocks at the readobject phase and I don't know why
In other mean, the first UIhelper in the client code is printing a reference while the second UIhelper is not
Please need your help
Server Code
public void revokeUser(String userid){
try {
Connection conn = Config.getConnection();
PreparedStatement stat = conn.prepareStatement(sql);
stat.setString(1,userid);
stat.setInt(2, listno);
stat.setInt(3, counter);
stat.execute();
revokeUserzz(userid,listno, counter);
} catch (SQLException e) {
e.printStackTrace();
}}
private void revokeUserzz(String userid, int listno, int counter) {
RevokedUser revoke = new RevokedUser();
revoke.setuserName(userid);
revoke.setlistNumber(listno);
revoke.setcounter(counter);
try {
ServerSocket serversocket = new ServerSocket(4400);
System.out.println("listening: 8888");
Socket socket = serversocket.accept();
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(revoke);
System.out.println("UserName: " +revoke.getuserName());
System.out.println("ListNumber: " +revoke.getlistNumber());
System.out.println("Counter: " +revoke.getcounter());
serversocket.close();
socket.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Client Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Socket socket;
ObjectInputStream ois = null;
try {
socket = new Socket("192.168.1.115", 4400);
ois = new ObjectInputStream(socket.getInputStream());
UIHelper.displayText(this, R.id.textView1, "Object =\n" +ois.toString());
RevokedUser revoke = (RevokedUser) ois.readObject();
UIHelper.displayText(this, R.id.textView3, "Object =\n" +revoke.getuserName().toString());
}
}
/////////////////////////////////////////////////////////////////
Serialized Code
public class RevokedUser implements Serializable {
private static final long serialVersionUID = -86055680657258429L;
private int listNumber;
private int counter;
private String userName;
public RevokedUser() {
}
public int getlistNumber() {
return listNumber;
}
public void setlistNumber(int listNumber) {
this.listNumber = listNumber;
}
public int getcounter() {
return counter;
}
enter code here
public void setcounter(int counter) {
this.counter = counter;
}
enter code here
public String getuserName() {
return userName;
}
public void setuserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "RevockedUser{" +
"userIds='" + userName + '\'' +
", listNumber=" + listNumber +
", counter=" + counter +
'}';
}