6 Replies Latest reply on Jul 29, 2014 12:31 AM by Madhusudhan Reddy

    'net-http' issue with iphone simulator

    Madhusudhan Reddy

      Hi All,

       

      I'm calling web-services in my rhomobile application, am able to get the result in rhosimulator(iPhone) with no errors, but when am trying to run the application on device(iPhone and iPhone simulator(using rake run:iphone)) my controller is working.

      I tried by removing the 'net-http' extension and require 'net/http' so it is working. but I cant call web-services.

      How to make it run on iPhone.

      Please suggest solutions.

       

       

      -Thanks.

        • Re: 'net-http' issue with iphone simulator
          Jon Tara

          You don't need net-http to access web services. That's what the Net API is for. (Or the old AsyncHTTP). It's a much better choice, because net-http is blocking and as a practical matter you need to use it in a separate thread. And that's only supported on some platforms. (Works on iOS, doesn't on Android.)

           

          The Net API is much better for general use because it uses Rhodes callbacks and doesn't need a separate thread to run asynchronously.

           

          net-http is useful if you are porting some existing software that needs net-http.

           

          In fact, I use net-http in an app (I ported XMPP4R to Rhodes: watusi/xmpp4r · GitHub ). I haven't tried this with recent Rhodes versions, though.

           

          Unclear from your post what is/isn't working. The heading says issue with simulator. The body of your post seems to say it works on simulator and also that it works on the device. Can you clarify?

            • Re: 'net-http' issue with iphone simulator
              Madhusudhan Reddy

              Jon Tara,

               

              Thanks for the reply. When am running the code in the rhosimulator(iPhone) it is working properly,In the devise(iPhone) it is not working.

               

              -Thanks

                • Re: 'net-http' issue with iphone simulator
                  Jon Tara

                  Do you need to use net-http? Is this an already-developed app and you are doing a version upgrade?

                   

                  I would avoid net-http. You can't do non-blocking operations without a thread. It's essentially not usable on Android. Use Rhodes Net API.

                   

                  Define "not working". Do your devices have access to the server(s) you are trying to access? Did you test out connectivity independently of Rhodes?

                    • Re: 'net-http' issue with iphone simulator
                      Madhusudhan Reddy

                      Jon Tara,


                      It is not already built application, am building this application in that I need to call the web-service.


                      this is my sample code

                          http = Net::HTTP.new('www.example.com', 8080)

                          path = '/webservice.asmx'

                          data = '<?xml version="1.0" encoding="utf-8"?>

                                    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                     xmlns:xsd="http://www.w3.org/2001/XMLSchema"                                             xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

                                           <soap:Body>

                                            <CelsiusToFahrenheit xmlns="http://tempuri.org/">

                                            <Celsius>#{celsius}</Celsius>

                                            </CelsiusToFahrenheit>

                                      </soap:Body>

                                    </soap:Envelope>'

                          headers = {

                                      'Content-Type' => 'text/xml',

                                      'Content-Length' => 'length',

                                      'charset' => 'utf-8',

                                      'SOAPAction' => "http://tempuri.org/UserLogin",

                                      'Host' => 'example.co'

                                     }

                       

                          resp, data = http.post(path, data, headers)

                       

                      ''This code is working in the rhosimulator but not working in iPhone", yes my device is allowed call the

                       

                      I have tried this using Rho::Network, but am getting 400 error. (Rhosimulator)

                      If it is possible please let me know how to write it in Rho::Network.post().

                      Am not using RhoConnect.

                       

                      Yes my device is allowed to call this web-service.

                       

                      -Thanks

                        • Re: 'net-http' issue with iphone simulator
                          Jon Tara

                          You said in your first post it is working on simulator but not on device. So, that's wrong, and it's working on the device but not in the simulator?

                           

                          400 error means your server didn't like the syntax of the URL (or that's what it SHOULD mean - in any case, your server returned a 400 error). Check your server logs and see why your server gave a 400 error.

                           

                          Unfortunately, I don't think RhoSimulator has a simulated browser you can use to test (like in real iPhone simulator, for example) or the first thing I would do is type the URL into a browser navigation bar. Try your desktop browser. Can you access the URL from there?

                           

                          net-http is not practical for most Rhodes applications. It is not going to give you a usable app. Everything has to be synchronous, or you have to use a thread. But you can't use a thread on Android. If you can't use a thread, then your app will not be responsive while a network request is outstanding. That is not usable.

                           

                          I don't know about Rho Simulator. I don't use it. I use native simulator. (e.g. for iOS, iPhone/iPad Simulator that comes with Xcode, for Android, the simulator that comes with the development kit. Etc. You should have no difficulty with those.

                           

                          If you think there is a bug with Rho Simulator, create an Issue on Github.

                  • Re: 'net-http' issue with iphone simulator
                    Madhusudhan Reddy

                    No, it was working on simulator but not on the device.

                     

                    Thanks for the advise finally I made it work on device.