DevkitPro DSWifi Connection Help!

Discussion in 'NDS - Emulation and Homebrew' started by madeinair, Dec 5, 2013.

  1. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    If anyone with homebrew knowledge could please help me out.
    I'm trying to developed client/server application where the client is the DS and server is the PC, I've tried using the HTTPGET example code in the devkitpro examples, I'm able to connect to other HTTP servers, but when I try to connect to mine it always fails, fails at the line:

    connect( my_socket,(struct sockaddr *)&sain, sizeof(sain) );

    I've disabled firewall on port 80, I'm able to access the HTTP page through firefox by typing my IP address, but when I try to connect with the DS it doesn't accept (I've tried this in both Desmume and actual DS hardware).

    The code before the connect is this:

    -------------------------------------------------------------------------
    struct hostent * myhost = gethostbyname( url );
    iprintf("Found IP Address!\n");

    // Create a TCP socket
    int my_socket;
    my_socket = socket( AF_INET, SOCK_STREAM, 0 );
    iprintf("Created Socket!\n");

    // Tell the socket to connect to the IP address we found, on port 80 (HTTP)
    struct sockaddr_in sain;
    sain.sin_family = AF_INET;
    sain.sin_port = htons(80);
    sain.sin_addr.s_addr= *( (unsigned long *)(myhost->h_addr_list[0]) );
    -------------------------------------------------------------------------

    I'd greatly appreciate any help ! :)
     
  2. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,528
    21,456
    Sep 13, 2009
    Poland
    Gaming Grotto
    Are you 100% sure that you're forwarding the ports? Can you access the server from other external devices, not just the host itself?
     
  3. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    Yes, I was able to access the server webpage from an android phone, just by accessing my IP address.
     
  4. ipwndeveloper

    ipwndeveloper GBAtemp Regular

    Member
    276
    68
    Jun 3, 2013
    United States
    San Fransisco, CA
    Did you include the libraries(in addition to the usual nds.h)?
    Code:
    #include <dswifi9.h>
    #include <netdb.h>
    #include <string.h>
    #include <netinet/in.h>
    #include <sys/socket.h>
    Also don't forget to via the WFC Data if you do not plan to create your own lib to connect. The code below checks to see if it can connect to http://google.com
    Code:
    int main(void) {
        consoleDemoInit();
        ifprint("Connecting...\n");
        if(Wifi_InitDefault(WFC_CONNECT)) {
          ifprintf("Yo, You best check your wifi settings, It failed to connect bro");
    } else {
      ifprintf("It actually Worked! Connected.\n\n");
    getHttp("http://google.com")
     
          while(1) {
              swiWaitForVBlank();
        }
        return 0;
    }
    Good Luck!
     
  5. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    Thanks for the suggestion!
    The example code HTTPGET already contains the checks:
    ----------------------------------------------------------------------------------
    if(!Wifi_InitDefault(WFC_CONNECT)) {
    iprintf("Failed to connect!");
    } else {
    iprintf("Connected\n\n");
    getHttp("192.168.1.5");
    }

    while(1) {
    swiWaitForVBlank();
    }
    ----------------------------------------------------------------------------------
    And all the libraries are added.
    When I try to connect to Google or any other web server, the connection works absolutely fine !!
    The problem is when I try to connect to my own web server (192.168.1.5), typing 192.168.1.5 in firefox shows the webpage but accessing it through the HTTPGET ds homebrew example doesn't work.
    I also know that having the IP address as a parameter in getHttp works, tried it with the IP address of GBATemp and it got past the connection stage.
     
  6. ipwndeveloper

    ipwndeveloper GBAtemp Regular

    Member
    276
    68
    Jun 3, 2013
    United States
    San Fransisco, CA
    ahh, try adding this instead
    Code:
    getHttp("http://192.168.1.5");
    of just the IP address. May I ask what you are making?
     
  7. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    I've already tried that T_T.
    I've tried ur suggestion, adding ":80", trying https, all possible combinations but same problem.
    I'm trying to make a homebrew for sharing files from DS to PC :), I've programmed in C before (even sockets) but have no idea why I can't get past the connection stage.
    On the server side, i'm also running Accept but it's not even reaching it.
     
  8. ipwndeveloper

    ipwndeveloper GBAtemp Regular

    Member
    276
    68
    Jun 3, 2013
    United States
    San Fransisco, CA
    Wow, that is strange, perhaps its an error with the DS WiFi Stack connecting to intranet ip adresses(although I recall it working in the past), I havent been able to compile work on any DS Wireless projects in a while, due to having a WPA2 AES router and more importantly the DSWifiLib will not compile on my OS for some reason, I have yet to discover. I mainly the program work in emulation and other math/decoder projects. Wintermute (the guy who developed Devkit ARM) on their fourms. I wish I could help more but my experience with the using the DS wifi abilities is limited, If I think of something I'll be back. Also if you fix your whatever the issue is, do PM me, as I am in need of a good wifi enabled file transfer as my acekards spring is about to give out!
     
  9. KazoWAR

    KazoWAR GBAtemp Advanced Maniac

    Member
    1,791
    673
    Aug 12, 2008
    United States
    Winter Haven
    you might need to edit request_text in getHttp
     
  10. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    Yep, i've already edited the request_text variable, the value now is:
    ----------------------------------------------------------------------------------
    GET / HTTP/1.1
    Host: 192.168.1.5
    User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Cache-Control: max-age=0
    ----------------------------------------------------------------------------------
    Thanks for the suggestion!
     
  11. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    762
    284
    Jul 28, 2008
    United States
    are your ds and your pc connecting to the same access point? some APs use different networks with different ssids for 5 GHz vs 2.4 GHz. and you can have rules about wired device being accessible by wireless. use a packet sniffer (netmon works well in windows) and see if the ds packets are visible to your pc.
     
  12. madeinair
    OP

    madeinair Advanced Member

    Newcomer
    50
    2
    Jul 16, 2011
    I've solved the problem !!!
    The issue was port 80 only allowed secure http connections, the android device connected to my IP with https, whilst the ds tried to connect with http only and got rejected, to solve the problem I allowed port 80 to accept any http connection (secure or not) and now it's working great!
    Thanks guys :D
     
  13. ipwndeveloper

    ipwndeveloper GBAtemp Regular

    Member
    276
    68
    Jun 3, 2013
    United States
    San Fransisco, CA
    *Claps*
    Congrats mate!
    Looking forward to a release