 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
steffven
Joined: 19 May 2008 Posts: 28
|
Posted: Mon May 19, 2008 7:46 pm Post subject: Send message over wlan on exiting game |
|
|
I wrote a wifi application which communicates with my pc.
How can i send a message to my pc when the application is left (HOME --> yes)? I know how to send messages but i dont know how i know that the application is left. |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Tue May 20, 2008 12:07 am Post subject: |
|
|
You should already know how to setup a callback thread...if not refer to the file "pspdev\psp\sdk\samples\gu\common\callbacks.c".
In function exitCallback() insert your own code:
| Code: | int exitCallback(int arg1, int arg2, void *common)
{
// do whatever you want here
exitRequest = 1; // main program loops should check for exitRequest
return 0;
}
void main()
{
while(!exitRequest)
{
// ...
}
sceKernelExitGame();
}
|
Grab any other wifi specific code from sdk examples....
Good luck,
jean |
|
| Back to top |
|
 |
steffven
Joined: 19 May 2008 Posts: 28
|
Posted: Tue May 20, 2008 12:28 am Post subject: |
|
|
| Code: | int exit_callback(int arg1, int arg2, void *common)
{
write(new, "exiting", strlen("exiting"));
sceKernelExitGame();
return 0;
} |
I already tried exactly that code but it exits without sending anything |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Tue May 20, 2008 12:35 am Post subject: |
|
|
....i bet it's not "exactly" the same.
1) don't know of all the code around to register the exit handler you wrote
2) you should NOT use sceKernelExitGame() from inside the exit handler, but instead accordingly set a variable that main loop checks against.
3) you start a communication routine a millisecond before the program context gets cleaned because of the issued exit command...At least put a sleep after the string printout.
PS: if you post some critical points of your code, this could help us helping you. |
|
| Back to top |
|
 |
steffven
Joined: 19 May 2008 Posts: 28
|
Posted: Tue May 20, 2008 12:50 am Post subject: |
|
|
| Code: | int exit_callback(int arg1, int arg2, void *common)
{
write(new, "exiting", strlen("exiting"));
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int net_thread(SceSize args, void *argp)
{
//All my code in here
}
int main(int argc, char **argv)
{
SceUID thid;
SetupCallbacks();
pspDebugScreenInit();
# ifdef PSPFW3
sceUtilityLoadNetModule(1);
sceUtilityLoadNetModule(3);
# else
if (pspSdkLoadInetModules() < 0) {
CenterPrintF(RED, 0, "Not able to load network modules!\n");
sceKernelSleepThread();
}
# endif
thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if(thid < 0)
{
printf("Thread could not be created\n");
sceKernelSleepThread();
}
sceKernelStartThread(thid, 0, NULL);
sceKernelExitDeleteThread(0);
return 0;
} |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|