Android HTTP Connection


Can anybody tell my why this doesn't work in the Android emulator? From the browser I have access and the server is internal. All I can think of is that I'm missing some configuration on my app so it can access the network layer.

try {
    InetAddress server = Inet4Address.getByName("thehost");
    //Doesn't work either
    //or InetAddress server2 = Inet4Address.getByAddress(new String("").getBytes());

        Log.d(TAG, "Ping!");

    Socket clientsocket = new Socket(server, 8080);
} catch (UnknownHostException e) {
    Log.e(TAG, "Server Not Found");
} catch (IOException e) {
    Log.e(TAG, "Couldn't open socket");

Throws an UnknownHostException



I see you've accepted an answer and don't plan to continue in this vein, but I am curious whether you could achieve something like you wanted by implementing this:

- (BOOL)canBecomeFirstResponder
   return !preventingKeyboardAppearance; // so to speak

- (void)searchBar:(UISearchBar *)filterBar textDidChange:(NSString *)filterText 
   // handle text

   preventingKeyboardAppearance = YES;
   [filterBar resignFirstResponder];

I'm not clear under what circumstances you would set preventingKeyboardAppearance back to NO, but I do wonder if this would work.

I basically agree with Kevin, but that doesn't help you so here goes:

Try looping through the subviews of the searchbar and find the sibling which is of the class UITextField. Then either set the delegate property of this text field to your ViewController's class and handle the callback there (e.g. textViewShouldReturn), or simply call resignFirstResponder directly on the text field. The former obviously needs to be done at init/load time while the latter can be done in your existing textDidChange callback.

Here are some more pointers:

This video can help you solving your question :)
By: admin