hate these ads?, log in or register to hide them
Page 5 of 8 FirstFirst ... 2345678 LastLast
Results 81 to 100 of 152

Thread: Dumb Programming Questions - Pro Programming Answers Megathread!

  1. #81
    balistic void's Avatar
    Join Date
    May 5, 2011
    Location
    Dublin/London
    Posts
    1,827
    Put breakpoint and inspect the value of "Test".

  2. #82

    Join Date
    September 13, 2011
    Location
    Norway
    Posts
    573
    Quote Originally Posted by balistic void View Post
    Put breakpoint and inspect the value of "Test".
    Value of test is correct and is a string.

    This does not equal 0 for whatever reason.
    If DnsQuery(sAddr, DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then

  3. #83
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Anyone done Android <-> WCF?

  4. #84
    balistic void's Avatar
    Join Date
    May 5, 2011
    Location
    Dublin/London
    Posts
    1,827
    Quote Originally Posted by IceBlock View Post
    Quote Originally Posted by balistic void View Post
    Put breakpoint and inspect the value of "Test".
    Value of test is correct and is a string.

    This does not equal 0 for whatever reason.
    If DnsQuery(sAddr, DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then
    You think value of test is correct, does the program?

    Put

    if (test == "google.com")
    msgbox "shizzle looks good"
    else
    msgbox "wtfffff"

    Might be some weird character encoding thing.

  5. #85

    Join Date
    June 6, 2011
    Posts
    255
    Quote Originally Posted by Dark Flare View Post
    Anyone done Android <-> WCF?
    Moar details. Your app trying to consume a existing WCF service? Need to implement both? If the WCF service provides a SOAP/REST interface it should be straight forward.

  6. #86
    Donor
    Join Date
    April 11, 2011
    Location
    The Netherlands
    Posts
    680
    Quote Originally Posted by Irrelephant View Post
    Quote Originally Posted by Dark Flare View Post
    Anyone done Android <-> WCF?
    Moar details. Your app trying to consume a existing WCF service? Need to implement both? If the WCF service provides a SOAP/REST interface it should be straight forward.
    This, Android works best with REST, because it's a lot more lightweight than SOAP (mobile latency/bandwidth). A WCF service can expose a REST interface fairly trivially.

  7. #87

    Join Date
    September 13, 2011
    Location
    Norway
    Posts
    573
    Quote Originally Posted by balistic void View Post
    Quote Originally Posted by IceBlock View Post
    Quote Originally Posted by balistic void View Post
    Put breakpoint and inspect the value of "Test".
    Value of test is correct and is a string.

    This does not equal 0 for whatever reason.
    If DnsQuery(sAddr, DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then
    You think value of test is correct, does the program?

    Put

    if (test == "google.com")
    msgbox "shizzle looks good"
    else
    msgbox "wtfffff"

    Might be some weird character encoding thing.
    Thank you. I made an assumptation that it would take the value directly without adding whitespace. So Trim() Solved it. -_-

    EDIT:
    What a load of brainfuck Win32 API is compared to .NET.
    Last edited by IceBlock; May 24 2012 at 09:15:26 AM.

  8. #88
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Quote Originally Posted by Waagaa View Post
    Quote Originally Posted by Irrelephant View Post
    Quote Originally Posted by Dark Flare View Post
    Anyone done Android <-> WCF?
    Moar details. Your app trying to consume a existing WCF service? Need to implement both? If the WCF service provides a SOAP/REST interface it should be straight forward.
    This, Android works best with REST, because it's a lot more lightweight than SOAP (mobile latency/bandwidth). A WCF service can expose a REST interface fairly trivially.
    Yes but I'm bad and didn't know Android til 2 days ago >.>

    Current problem: How do I shot threading.

  9. #89
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    MULTITHREADING SUCCESS.

    New problem
    org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8732 refused
    Y U NO LET ME

  10. #90

    Join Date
    April 10, 2011
    Posts
    7,014
    You have something listening on that port, right?
    Firewall? It's above the usual 1024 restricted range...

    Edit: Is it because your Android emulator doesn't have something running there, instead that's on your local physical machine, so you need to traverse the network correctly to break out of the VM? Try using an IP address.
    http://developer.android.com/resourc...localhostalias
    Referring to localhost from the emulated environment

    If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.
    Last edited by Daneel Trevize; May 24 2012 at 10:34:47 AM.

  11. #91
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Yes it is that. I am an idiot.

    Now I've almost got there, it's getting the response from the web service, but it's not setting it to the textbox output for fuck only knows what reason.

    // Read response data
    char[] buffer = new char[(int)responseEntity.getContentLength()];
    InputStream stream = responseEntity.getContent();
    InputStreamReader reader = new InputStreamReader(stream);
    reader.read(buffer);
    stream.close();

    JSONArray helloresponse = new JSONArray(new String(buffer));

    tv.setText(helloresponse.toString());
    tv.setVisibility(View.VISIBLE);


    Y U NO GO

    (helloresponse contains the information i would expect, btw)

    EDIT: FIXT
    Last edited by Dark Flare; May 24 2012 at 11:42:06 AM. Reason: FIXT

  12. #92
    Donor
    Join Date
    April 11, 2011
    Location
    The Netherlands
    Posts
    680
    Quote Originally Posted by Dark Flare View Post
    Yes it is that. I am an idiot.

    Now I've almost got there, it's getting the response from the web service, but it's not setting it to the textbox output for fuck only knows what reason.

    // Read response data
    char[] buffer = new char[(int)responseEntity.getContentLength()];
    InputStream stream = responseEntity.getContent();
    InputStreamReader reader = new InputStreamReader(stream);
    reader.read(buffer);
    stream.close();

    JSONArray helloresponse = new JSONArray(new String(buffer));

    tv.setText(helloresponse.toString());
    tv.setVisibility(View.VISIBLE);


    Y U NO GO

    (helloresponse contains the information i would expect, btw)

    EDIT: FIXT
    Could be an encoding thing. Can you get the encoding of the responseEntity? I'm pretty sure there's a String constructor that allows you to supply encoding too.
    Also, try outputting new String(buffer) instead, a JSON response is just a String..

  13. #93
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Yup, got it.

    Now time to build in authentication! This will be an interesting day.

  14. #94
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Okay so kinda working.

    The string I get back from the Auth is like so:
    {"Authed":true,"Level":1,"Name":"test"}

    What's the best way to split up and handle this data? It's a JSON response if that makes any difference. Basically what I want it to do at this stage is push to a new screen (via Intent, is that right for UI flow?) where it'll display a list of things based on what the level set is (higher level can see MOAR THINGS), and also output the name at the top of the screen or something (which I know how to do, obv, I just don't know how to split up that data that's passed back from the call).

  15. #95
    halka's Avatar
    Join Date
    April 19, 2011
    Location
    Tarnished Coast
    Posts
    928
    Isn't there a JSON deserializer (which should unpack the data into an array or an object) built-in?

    ed: haven't really tried my hand at this whole mobile developemnt thing so I'm not sure what resources you have at our disposal, but System.Web.Extensions.dll.JavaScriptSerializer (.NET 3.5) should be able to parse it.
    Last edited by halka; May 25 2012 at 12:16:57 PM.
    All expressed opinions match those of my employers, hail satan

  16. #96
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Sorry I should have specified, it's on the android that I wish to turn it into something I can manipulate.

  17. #97
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    By jove I do believe I'm getting there. Can now handle it as an object and interrogate the properties.

    Now I just need to use the interrogation of the "Authed" property to decide whether or not to pass to a NEW SCREEN.

  18. #98

    Join Date
    April 10, 2011
    Posts
    7,014
    I do hope you're not trusting the response from the network as to whether a secret/secure screen should be displayed. Sure you have the server dictate what level a user is at, and then decide to present them controls or not with which to send different requests to the server, but please don't be having some privileged info in your android client that you will reveal to someone/anyone who manages to supply some specific text in a HTTP response.

  19. #99
    Movember 2012Donor Dark Flare's Avatar
    Join Date
    April 9, 2011
    Posts
    3,599
    Yeah the new screen is just going to be a series of buttons that fire off further web calls to the server with credentials from the phone, don't worry!

  20. #100
    Tarminic's Avatar
    Join Date
    April 9, 2011
    Location
    Nashville, TN
    Posts
    2,908
    Another programming question, this one work-related.

    NOTE: The language I'm working with is PHP 5.3something
    Currently, my work codebase has a bunch of controllers classes that extend a Secure_Controller class. They also have various AJAX functions for retrieving data, none of which are really standardized - leading to potential security issues, duplicated code, etc. I want to solve this by creating a standarized function that all AJAX calls will pass through. My initial idea (a shitty one) was to do something like this:

    Code:
    class Derp extends Secure_Controller {
        public function ajax($urlSegment) {
            $params = $this->input->post();
            switch($urlSegment) {
                case 'poop':
                    $data = $this->doSomething($params['haduuuur']);
                    break;
                case 'urinateViolently':
                    $data = $this->doSomethingElse($params['herp'];
                    break';
                //so on and so forth
           }
           $this->output->set_header('Content-type:application/json');
           $this->output->set_output(json_encode($data));
        }
    }
    So the URL /derp/ajax/urinateViolently will call Derp::doSomethingElse()


    Except that's terrible - you have to update the function EVERY TIME you want to enable another AJAX call. It's not that much better than just implementing them without any kind of consistency.

    This led me to another idea, however - implement an AJAX delegate function in the secure controller class and using a string at the end of the functions to denote its availability to be used for an AJAX call:

    Code:
    class Secure_Controller {
    
        public function ajax($task) {
            $params = $this->input->post();
            $functionName = $task . 'ForAjax';
            $data = array();
            if(method_exists($this, $functionName) {
                $data = $this->$functionName($params);
            }
            $this->output->set_header('Content-type:application/json');
            $this->output->set_output(json_encode($data));
        }
    }
    Thus, the functions being implemented here would look something like this:
    Code:
    Derp::pooForAjax($params) /* called from /derp/ajax/poo */
    Derp::urinateViolentlyForAjax($params) /* called from /derp/ajax/urinateViolently */
    The primary downside of this is that if some dumb shit just happens to use a function that ends with "ForAjax" its output will end up returned, but I've checked the codebase and there are no such functions. I feel like I can do better than this, but I don't want developers to have to manually update a registry of AJAX-capable functions. What's your input, FHC programmers?
    Last edited by Tarminic; May 30 2012 at 11:38:58 PM.

    Status of Babby: 100% Formed

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •