Reading from a socket in a while loop-Collection of common programming errors
I want to implement the following functionality
while (true)
{
if client sends something
process it
else wait till something is send }
I have tried the following but it didn’t work , it process one thing and then stop working can anyone help me? I have searched for such a case here but I didn’t find anything . I would appreciate it if anyone can give an example of how to read from the socket inside a while loop as in the above description .
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));
DataOutputStream outToclient =new DataOutputStream(client.getOutputStream());
while (true){
if ((request=inFromClient.readLine())!=null){
System.out.println("ser "+request);
msg1= new msgs();
if(msg1.IsListReq(request))
{
System.out.println("Ser :List req");
for (int i = 0; i