Note that there are some explanatory texts on larger screens.

plurals
  1. PONetwork timed out exception
    primarykey
    data
    text
    <p>I have an Android application which connects to an Arduino server and sends it sockets on a button press, but as soon as I press the button it waits a little while and then throws "Connection timed out". I know the Arduino works; I tried it over the browser and it was fine. Why can't my application access it?</p> <p>The Android code:</p> <pre><code>Button.OnClickListener buttonConnectOnClickListener = new Button.OnClickListener() { public void onClick(View v) { Log.i(Tag,"connecting to Server"); try { Log.i(Tag,"Enters try"); socket = new Socket("161.53.168.112", 8888); Log.i(Tag,"stvorio socket"); dataOutputStream = new DataOutputStream(socket.getOutputStream());//and stream Log.i(Tag,"Writing 1 on socket."); dataOutputStream.writeBytes("1"); } catch (UnknownHostException e) { Log.i(Tag,e.toString()); } catch (IOException e) { Log.i(Tag,e.toString()); } catch (Exception e) { Log.e(Tag, e.toString()); </code></pre> <p>And here is the code used in the Arduino. It's quite simple, so I can't understand what went wrong. I used many logs, because I wanted to see where the mistake is. I use my Arduino as a server and post something on it. If I type in 161.53.168.112:8888 in a web browser, it finds it and can send a request but my Android phone gets nothing, even using the browser, and not an app. I can't access my server. AM I maybe missing some permission in the server or on the Android?</p> <pre><code>byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x36, 0xFF }; byte ip[] = { 161, 53, 168, 114 }; int serverPort = 8888; #define kitchenLight = 9; Server server(serverPort); void setup() { Serial.begin(9600); Ethernet.begin(mac, ip, gateway, subnet); pinMode(kitchenLight,OUTPUT); server.begin(); } void loop() { Client client = server.available(); if(client) { while(client.connected()) { if(client.available()) { char c = client.read(); appMessage += c; if (c == '\n') { Serial.println("Message from Client: "+appMessage); if(appMessage.IndexOf("kitchenLight1") != -1) { digitalWrite(kitchenLight,HIGH); } } } } } client.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload