So i have this application in which I am storing Sockets in an ArrayList on the Server side. When the client closes its application the socket must close as well but It doesnt reflect the changes in the ArrayList in the server.
class arrays
{
public static ArrayList<Socket> online_buyer=new ArrayList<Socket>();
public static ArrayList<Socket> online_seller=new ArrayList<Socket>();
public static ArrayList<String> buyer_prod=new ArrayList<String>();
}
public void seller_display()
{
while(true)
{
if(flag==1)
{
synchronized(sock)
{
for(int i=0;i<arrays.online_buyer.size();i++)
{
System.out.println(arrays.buyer_prod.get(i));
}
flag=0;
}
}
check2();
}
}
public void check2()
{
for(int i=0;i<arrays.online_buyer.size();i++)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
**while(!arrays.online_buyer.get(i).isConnected())**
{
arrays.online_buyer.remove(i);
arrays.buyer_user.remove(i);
arrays.buyer_add.remove(i);
arrays.buyer_prod.remove(i);
arrays.time.remove(i);
arrays.buyer_no.remove(i);
flag=1;
System.out.println("RECORD DELETED");
}
}
}
public void run()
{
get_details();
}
}
Now the statement while(!arrays.online_buyer.get(i).isConnected()) must be while(!false)=true. When i close the socket from the client side as isconnected()method must return false. But this statement never runs to be false even if i close the socket from client.