{"id":5346,"date":"2014-03-30T20:58:54","date_gmt":"2014-03-30T20:58:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/reading-from-a-socket-in-a-while-loop-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:58:54","modified_gmt":"2014-03-30T20:58:54","slug":"reading-from-a-socket-in-a-while-loop-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/reading-from-a-socket-in-a-while-loop-collection-of-common-programming-errors\/","title":{"rendered":"Reading from a socket in a while loop-Collection of common programming errors"},"content":{"rendered":"<p>I want to implement the following functionality<\/p>\n<pre><code>while (true)\n{\nif client sends something \nprocess it\n\nelse wait till something is send }\n<\/code><\/pre>\n<p>I have tried the following but it didn&#8217;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&#8217;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 .<\/p>\n<pre><code>            BufferedReader inFromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));\n            DataOutputStream outToclient =new DataOutputStream(client.getOutputStream());\n            while (true){\n                if ((request=inFromClient.readLine())!=null){\n\n\n                        System.out.println(\"ser \"+request);         \n                        msg1= new msgs();\n                        if(msg1.IsListReq(request))\n                        {\n                               System.out.println(\"Ser :List req\");\n\n\n\n                               for (int i = 0; i<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t work , it process one thing and then stop working can anyone help me? I have searched for such a case here but I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5346","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5346"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5346\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}