1. Are you ready for the Galaxy S20? Here is everything we know so far!

GET method with original server

Discussion in 'Android Development' started by konoka, Apr 25, 2012.

  1. konoka

    konoka Lurker
    Thread Starter

    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 (Text):
    1.         public void sendMessage(String strQuery){
    2.             HttpGet httpget = new HttpGet("http://192.168.32.240:5000/"+strQuery);
    3.             //HttpGet httpget = new HttpGet("http://twitter.com/"); //test
    4.  
    5.             DefaultHttpClient client = new DefaultHttpClient();
    6.             try {
    7.                 HttpResponse httpResponse = client.execute(httpget);
    8.                 this.showMessage(Integer.toString(httpResponse.getStatusLine().getStatusCode()));
    9.                 client.getConnectionManager().shutdown();
    10.             } catch (ClientProtocolException e) {
    11.                 this.showMessage("bad protocol");
    12.             } catch (IOException e) {
    13.                 this.showMessage("IOException");
    14.             }
    15.  
    16.         }
    server(C#):
    Code (Text):
    1.         void startServer()
    2.         {
    3.             HttpListener listener = new HttpListener();
    4.             listener.Prefixes.Add("http://*:5000");
    5.             listener.Start
    6.             HttpListenerContext context = listener.GetContext();
    7.             Console.WriteLine(con.Request.RawUrl);
    8.             byte[] buffer = Encoding.Unicode.GetBytes("200");
    9.             context.Response.OutputStream.Write(buffer, 0, buffer.Length);
    10.         }
     



    1. Download the Forums for Android™ app!


      Download

       
  2. wubbzy

    wubbzy Well-Known Member

    Can you post the exception?

    Also try changing
    DefaultHttpClient client = new DefaultHttpClient();
    to
    HttpClient client = new DefaultHttpClient();
     
  3. konoka

    konoka Lurker
    Thread Starter

    wubbzy

    java.net.SocketException: The operation timed out

    thanks
     
  4. wubbzy

    wubbzy Well-Known Member

    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.
     
  5. jonbonazza

    jonbonazza Android Expert

    192 is a private IP address. It is the addressed used by your router for internal routing and is not accessible from outside of your local network. You need to use your public ip (go here: What Is My IP Address - Shows Your IP Address) and then forward port 5000 to 192.168.32.240 from within your routers admin settings.
     
Loading...
Similar Threads - method original server
  1. Troubleshooter03
    Replies:
    2
    Views:
    588
  2. Teofel Ervenge
    Replies:
    8
    Views:
    1,394
  3. Rgarner
    Replies:
    2
    Views:
    1,096
  4. Gobshyte
    Replies:
    0
    Views:
    395
  5. genka3
    Replies:
    13
    Views:
    5,112
  6. neha goenka
    Replies:
    0
    Views:
    2,237
  7. kumaranil13k
    Replies:
    5
    Views:
    2,238
  8. Mtn Drew
    Replies:
    5
    Views:
    2,616
  9. kamieniarzk
    Replies:
    0
    Views:
    1,601
  10. katesfb
    Replies:
    0
    Views:
    2,105

Share This Page

Loading...