Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagramSocket.bind(); Socket exception: cannot assign requested address. Android Emulator
    primarykey
    data
    text
    <p>I am new to both Android and Java so I beg your pardon if my question is asked at the inappropriate group or forum. I made a .Net application for my company and recently they asked me to port it on Android so as to install it on Samsung Galaxy Tabs.</p> <p>First of all, I am using Eclipse, JDK 6, target platform android 2.2 and an Emulator with the GalaxyTab plugin. My operating system is Windows 7.</p> <p>This application, sends and receives messages to and from a certain controller on the network using UDP. In short my application uses a "DatagramSocket", binds it to a local "InetSocketAddress" and then launches a thread that listens for datagrams, while another thread sends requests to the controller upon the user's request. Here is a some code snippet:</p> <p>This is where I assign the local address and the socket:</p> <pre><code>try { loc_addr = new InetSocketAddress( Inet4Address.getByAddress( new byte[]{(byte) 192,(byte) 168,1,(byte)240}), 0xBAC0); //192.168.1.240 is the IP of my machine on the network } catch (UnknownHostException e) { ....... } try { soc = new DatagramSocket(); soc.setReuseAddress(true); soc.setBroadcast(true); soc.bind(loc_addr); } catch (SocketException e) { ....... } </code></pre> <p>This is where I listen for incoming datagrams:</p> <pre><code>try{ buf = new byte[1024]; receive_pac = new DatagramPacket(buf, 1024); soc.receive(receive_pac); if (receive_pac.getData() != null){ ....... } } </code></pre> <p>This is where I send data:</p> <pre><code>try { addr = (Inet4Address) Inet4Address.getByAddress (new byte[] {(byte) 192,(byte) 168,1,(byte) 255}); //The message I am sending should be broadcasted } catch (UnknownHostException e) { ...... } sendPacket = new DatagramPacket(buf, buf.length, addr, loc_addr.getPort()); try { soc.send(sendPacket); } catch (IOException e) { ...... } </code></pre> <p>Well when I use "soc.bind(...)" I receive the following exception: cannot assign requested address</p> <p>Then I receive a debug message (I don't know if it is relevant):</p> <pre><code>DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol </code></pre> <p>The application is working, I verified through "WireShark" that when I ask from the emulator to send the data to the controller, the controller replies back with the expected data correctly. However, the socket, in the application, on the emulator doesn't receive anything and stays blocked on the "Receive" call!</p> <p>Can anyone help me figure out what problem or error I have committed with the receiving part of my application!</p> <p>Any help is much appreciated,</p>
    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