Android HTTP Connection

Question!

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("192.168.1.30").getBytes());

    if(server.isReachable(5000)){
        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

Thanks



Answers

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:

http://discussions.apple.com/thread.jspa?threadID=1479468&tstart=0 http://discussions.apple.com/thread.jspa?messageID=8176608



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