Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid App: Address Family not Supported by Protocol
    primarykey
    data
    text
    <p>I am trying to have my Android application sent Telnet commands over a small network to another device, and whenever I declare the DatagramSocket it throws a SocketException saying: <strong>Address Family not Supported by Protocol</strong>. Here is my code below:</p> <pre><code> try { addr = InetAddress.getByName(ipAddress); sock = new DatagramSocket(); //SocketException created here //first message - cmd length = cmd.length(); message = cmd.getBytes(); packet = new DatagramPacket(message, length, addr, portAddr); sock.send(packet); //second message - highCMD length = highCMD.length(); message = highCMD.getBytes(); packet = new DatagramPacket(message, length, addr, portAddr); sock.send(packet); sock.close(); } catch (SocketException e) { AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(v.getContext()).create(); alertDialog.setTitle("Send High CMD Error!"); alertDialog.setMessage("SocketException"); alertDialog.show(); } catch (IOException e){ AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(v.getContext()).create(); alertDialog.setTitle("Send High CMD Error!"); alertDialog.setMessage("IOException"); alertDialog.show(); } } </code></pre> <p>Possible solutions I've considered but haven't made work:</p> <ol> <li>Emulator needs port redirect through development machine, which ports to use?</li> <li>I'm not using correct version of IP4/6, how is this set?</li> <li>Device uses TCP protocol, maybe I'm using the wrong socket type?</li> </ol> <p>Other Important Info:</p> <ol> <li>I've only run this on an Emulator</li> <li>Development Machine correctly sent telnet commands from Command Prompt</li> <li>Network consists of development machine, router, and device.</li> </ol> <p><strong>UPDATE: 2/9/11</strong></p> <p>I've changed this code to the following, but I'm still getting an exception:</p> <pre><code> try { addr = InetAddress.getByName(ipAddress); socketAddress = new InetSocketAddress(addr, portAddr); sock = new Socket(); sock.connect(socketAddress); sock.close(); } catch (SocketException e) { AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(v.getContext()).create(); alertDialog.setTitle("Send High CMD Error!"); alertDialog.setMessage("SocketException" + e.getMessage()); alertDialog.show(); } </code></pre> <p>The message from the exception says "Permission Denied." Does this mean that my device is blocking the socket from connecting?</p>
    singulars
    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.
    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