{"id":5339,"date":"2014-03-30T20:51:14","date_gmt":"2014-03-30T20:51:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/android-inputstream-read-i-can-not-read-anything-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:51:14","modified_gmt":"2014-03-30T20:51:14","slug":"android-inputstream-read-i-can-not-read-anything-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/android-inputstream-read-i-can-not-read-anything-collection-of-common-programming-errors\/","title":{"rendered":"Android &#8211; inputStream.read() &#8211; I can not read anything-Collection of common programming errors"},"content":{"rendered":"<p>I have a problem with read data from socket. I was trying solve my problem in different way and i think my code now is the simplest possible to test it. Android have a problem to read from socket and stop in this line( inStream.read() ). After 10s( socket.setSoTimeout ) i have a message &#8212;&#8212;-error: null. I want to read any data( 0-255 ) or -1, but nothing has happend. In PHP( on my server, my code) and PC( not my app ) everything is fine. What should I do?<\/p>\n<p>It is my first post, so i am sorry for possible mistakes. Thanks for your help!<\/p>\n<pre><code>try{\n    socket      = new Socket( \"192.168.0.150\", 502 );\n    socket.setSoTimeout( 10000 );\n\n    outStream   = new DataOutputStream( socket.getOutputStream() );\n    inStream    = new DataInputStream( socket.getInputStream() );\n\n    System.out.println(\"----------\" + outStream);\n    System.out.println(\"----------\" + inStream );\n\n    outStream.write( 0x01 );\n    outStream.write( 0x03 );\n    outStream.write( 0x10 );\n    outStream.write( 0x00 );\n    outStream.write( 0x00 );\n    outStream.write( 0x04 );\n    outStream.write( 0x40 );\n    outStream.write( 0xC9 );\n\n    outStream.flush();\n    System.out.println(\"----------ok 1\");\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/               \n\n\/\/  Thread.sleep( 50 );\n    System.out.println(\"----------Test1: \" + socket.isConnected() );\n    System.out.println(\"----------Test2: \" + socket.isInputShutdown() );\n\n    int dat = inStream.read();\n    System.out.println(\"----------ok2: \" );\n} catch( Exception e ){\n    e.printStackTrace(); \/\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a problem with read data from socket. I was trying solve my problem in different way and i think my code now is the simplest possible to test it. Android have a problem to read from socket and stop in this line( inStream.read() ). After 10s( socket.setSoTimeout ) i have a message &#8212;&#8212;-error: [&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-5339","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5339","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=5339"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5339\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}