DS to PC Example/Tutor needed

Post Reply
dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

DS to PC Example/Tutor needed

Post by dheart88 » Wed Mar 17, 2010 10:36 pm

DS to PC Example/Tutor needed

Hi everyone,
I need some help here. I'm trying to make 3d multiplayer racing game in NDS console, but i can't find any example of connecting PC to NDS via access point.

1.Can somebody provide me link or maybe some example that still working under the latest libNDS?
2.Is direct DS-DS connection really impossible for libWifi? or should I use AP as the mediator?

Sorry for my bad english. I appreciate any kind of help.

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: DS to PC Example/Tutor needed

Post by StevenH » Thu Mar 18, 2010 1:54 am

If you know how a client server works on a PC using standard socket then your 95% of the way towards a working example...

DS-DS comms is not possible using libWiFi at this moment in time.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: DS to PC Example/Tutor needed

Post by dheart88 » Tue Mar 23, 2010 4:53 am

So basicly I have to learn pc-to-pc communication first and then implement it in pc-to-ds communication?? What netwoking devices needed to connect pc to ds?? Actually I have 1 PC, 1 notebook(with wifi) and two DSes, can I connect both NDSes by connecting them to the notebook or I have to buy an AP?

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: DS to PC Example/Tutor needed

Post by dheart88 » Tue Mar 23, 2010 6:20 am

I want to ask, is connection between PC and DS done by UDP?or TCP can also take part

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: DS to PC Example/Tutor needed

Post by StevenH » Tue Mar 23, 2010 11:27 am

dheart88 wrote:So basicly I have to learn pc-to-pc communication first and then implement it in pc-to-ds communication??
Basically yes, the way that the dswifi lib works is exactly the same as a standard BSD sockets / network code works.
dheart88 wrote:What netwoking devices needed to connect pc to ds??
As long as you have a WiFi access point and your DS's can access the internet / play games over the internet then your all set.
dheart88 wrote:Actually I have 1 PC, 1 notebook(with wifi) and two DSes, can I connect both NDSes by connecting them to the notebook or I have to buy an AP?
Assuming that you have a router that's set up with WEP security then you don't need anything else.
dheart88 wrote:I want to ask, is connection between PC and DS done by UDP?or TCP can also take part
UDP, TCP you decide, as you have to code the server and the client, so you can use either.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: DS to PC Example/Tutor needed

Post by dheart88 » Tue Mar 23, 2010 12:11 pm

Thank you very much for your information.. is it possible to make DS-DS communication through AP?

Btw, is there official documentation about dswifi? I didn't find it in Devkitpro documentation.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: DS to PC Example/Tutor needed

Post by dheart88 » Thu Apr 08, 2010 6:47 pm

I'm trying to make DS-DS connection, by connecting them to An AP first... what is wrong with my code??? why the server can't receive data from client??? Some of this code commented in indonesian...

#include <nds.h>
#include <stdio.h>
#include <dswifi9.h>

#include <sys/types.h>
#include <netinet/in.h>

#include <sys/socket.h>
#include <netdb.h>

#define NOSTAT 0
#define SERVER 1
#define CLIENT 2
#define BUFFER_SIZE 4096

int ServerSockListen;
int ClientSockSend;
int server,client;
int statex=0;
char buffer[4096];

int main()
{
consoleDemoInit();

iprintf("\x1b[1;1HStart");

Wifi_InitDefault(false);

//Wifi_EnableWifi();
Wifi_ScanMode();

iprintf("Searching default AP\n");

// wait for "default" AP to show up in the known AP list
bool ketemu=false;
while (!ketemu)
{
int APs = Wifi_GetNumAP();
int i=0;
iprintf("\x1b[2;0HAPs:\n");
while (i<APs)
{
Wifi_AccessPoint wap;
Wifi_GetAPData(i,&wap);
iprintf(wap.ssid);
iprintf(" -\n");
if (strcmp(wap.ssid,"ngagel 10 no.25")==0)
{
Wifi_SetIP(0,0,0,0,0);
Wifi_ConnectAP(&wap,0,0,0);
ketemu = true;
i=9999; //biar keluar looping cepat
iprintf(" ketemu ap kos!! connecting..");
};
i++;
};
};

iprintf("connecting to AP ... ");

while (Wifi_AssocStatus()!=ASSOCSTATUS_ASSOCIATED) {
};

iprintf("associated\n");

printf("Press A for Client,\n B for Server");

struct sockaddr_in i_addr;
memset((void *)&server, '\0', sizeof(struct sockaddr_in));

ClientSockSend =socket(AF_INET, SOCK_DGRAM, 0);
//ServerSockListen=socket(AF_INET, SOCK_DGRAM, 0);

keysSetRepeat (20, 5);
while (1)
{
scanKeys();

u32 keysdownrepeat = keysDownRepeat();
if (statex==0)
{
if (keysdownrepeat & KEY_A)
{
statex=1;
printf("client mode on");
i_addr.sin_family = AF_INET;
i_addr.sin_port = htons(9091);
i_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);//htonl(0xC0A80015);
} else if (keysdownrepeat & KEY_B)
{
statex=2;
printf("server mode on");
i_addr.sin_family = AF_INET;
i_addr.sin_port = htons(9091);
}
}
else
if (statex==1)
{
if (keysdownrepeat & KEY_A)
{
sendto(ClientSockSend,"A",2,0, (struct sockaddr *) &i_addr, sizeof(i_addr));printf("A");
}else if (keysdownrepeat & KEY_B)
{
sendto(ClientSockSend,"B",2,0, (struct sockaddr *) &i_addr, sizeof(i_addr));printf("B");
} else if (keysdownrepeat & KEY_X)
{
sendto(ClientSockSend,"X",2,0, (struct sockaddr *) &i_addr, sizeof(i_addr));printf("X");
} else if (keysdownrepeat & KEY_Y)
{
sendto(ClientSockSend,"Y",2,0, (struct sockaddr *) &i_addr, sizeof(i_addr));printf("Y");
}
}
else
if (statex==2)
{
recvfrom(ClientSockSend, buffer, 4096, 0, (struct sockaddr *) &i_addr, sizeof(i_addr));

if (strcmp(buffer, "A") == 0)
{
printf("A ditekan");
} else if (strcmp(buffer, "B") == 0)
{
printf("B ditekan");
} else if (strcmp(buffer, "X") == 0)
{
printf("X ditekan");
} else if (strcmp(buffer, "Y") == 0)
{
printf("Y ditekan");
}
}
swiWaitForVBlank();
}

return 0;
}

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests