Send message over wlan on exiting game

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
steffven
Posts: 28
Joined: Mon May 19, 2008 7:37 pm

Send message over wlan on exiting game

Post by steffven »

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.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

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: Select all

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
steffven
Posts: 28
Joined: Mon May 19, 2008 7:37 pm

Post by steffven »

Code: Select all

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
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

....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.
steffven
Posts: 28
Joined: Mon May 19, 2008 7:37 pm

Post by steffven »

Code: Select all

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 &#40;pspSdkLoadInetModules&#40;&#41; < 0&#41; &#123;
    CenterPrintF&#40;RED, 0, "Not able to load network modules!\n"&#41;;
    sceKernelSleepThread&#40;&#41;;
  &#125;
# endif

	thid = sceKernelCreateThread&#40;"net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL&#41;;
	if&#40;thid < 0&#41;
	&#123;
		printf&#40;"Thread could not be created\n"&#41;;
		sceKernelSleepThread&#40;&#41;;
	&#125;

	sceKernelStartThread&#40;thid, 0, NULL&#41;;

	sceKernelExitDeleteThread&#40;0&#41;;

	return 0;
&#125;
Post Reply