• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps GET method with original server

konoka

Lurker
Apr 25, 2012
3
0
Japan
Hi,

I'm new on android app development, now creating client-server system, and both of them are made from scratch. Let me ask you a question.

I'm trying to send message from my client (android 2.2.1) to my server (C#, windows7) with GET method. Both of them look like working well: the client got 200 from Twitter, and the server got message when accessed from web browser.
However, the client throws IO Exception and the server gets nothing when tried with them (even with fire wall unenabled). Anyone know why?

thanks...konoka


client(android):
Code:
    	public void sendMessage(String strQuery){
    		HttpGet httpget = new HttpGet("http://192.168.32.240:5000/"+strQuery);
    		//HttpGet httpget = new HttpGet("http://twitter.com/"); //test

    		DefaultHttpClient client = new DefaultHttpClient();
    		try {
				HttpResponse httpResponse = client.execute(httpget);
				this.showMessage(Integer.toString(httpResponse.getStatusLine().getStatusCode()));
				client.getConnectionManager().shutdown();
			} catch (ClientProtocolException e) {
				this.showMessage("bad protocol");
			} catch (IOException e) {
				this.showMessage("IOException");
			}

    	}

server(C#):
Code:
        void startServer()
        {
            HttpListener listener = new HttpListener();
            listener.Prefixes.Add("http://*:5000");
            listener.Start
            HttpListenerContext context = listener.GetContext();
            Console.WriteLine(con.Request.RawUrl);
            byte[] buffer = Encoding.Unicode.GetBytes("200");
            context.Response.OutputStream.Write(buffer, 0, buffer.Length);
        }
 
wubbzy

java.net.SocketException: The operation timed out

thanks

This error is very self-explanatory - your app (whether on emulator or device) does not have route to 192 address scheme that your web-service is running on.

twitter is working since it is well known IP address. It seems like your 192 addresses "may be" an issue.

r u running on emulator or the device?

If you're running on device 192 address will only work if you enable WiFi & connect your phone to 192 address space that your web-server is on or put the web-server on a public IP and then have the device connect to it

As with emulator you should have no problem if your dev sys is on same network or has a way to route your web-server. You can verify this by opening up web browser inside the emulator and pointing it to your web service. Start debugging from there.

BTW above is just basic networking, nothing about android here; Hope it works for you.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones