Welcome! Log In Create A New Profile

Advanced

[Coding] IRC client, need some help

Posted by iSubaru 
[Coding] IRC client, need some help
December 05, 2009 10:35PM
Hello
I have tried a bit by myself but it looks like coding IRC client is not as easy as I wanted
There are 3 header files I tried to use:
#include < MLlib.h >
#include < sys/types.h >
#include < sys/socket.h >
But last two gives errors, dunno why, maybe DevkitPPC doesn't like Linux header files :P

My question is what libraries (and eventually where search for them) should I use to this task?

I'm using Linux with DevkitPPC and MLlibrary for now

Thank You for advance

iSubaru

EDIT #1
Fixed



Edited 2 time(s). Last edit at 12/05/2009 11:04PM by iSubaru.
Re: [Coding] IRC client, need some help
December 05, 2009 10:54PM
EDIT: Nevermind, fixed.



Edited 1 time(s). Last edit at 12/06/2009 01:44PM by SifJar.
Re: [Coding] IRC client, need some help
December 05, 2009 11:03PM
What the... I have been copying with files...I will try editing post, maybe there is some error, if that won't help I will write without [ code] Tag <_<
Sorry for problems
One sec

EDIT #1
Fixed, I had to put space between "<" and ">" and text...strange...it shouldn't parse unknown tags in < >

EDIT #2
I had somewhere Python simple script to connect to certain server so I will probably use it for tries but first I have to know what libraries I will need :(



Edited 2 time(s). Last edit at 12/06/2009 01:00AM by iSubaru.
Re: [Coding] IRC client, need some help
December 06, 2009 01:48AM
I think you want to import network.h, it should be in the libogc include dir (of you have the libogc source, it is in the lwip, lightweight ip, directory).

Call the function net_init() which returns a signed int, non-zero is an error.
net_socket( int, int, int ); returns a socket file descriptor, INVALID_SOCKET upon error.
Same as BSD sockets in general, but all functions are prefixed with net_.

EDIT:
For a simple example look at the PCToWii application, it has a Wii server, and the source is available. Pretty simple code, just look at the main function. It comes packed as a VC project, so no Makefile, but if you have Windows and VC Express, it makes things even easier.



Edited 1 time(s). Last edit at 12/06/2009 01:50AM by WiiGent.
Re: [Coding] IRC client, need some help
December 06, 2009 02:57AM
Thank You for reply :)
Now to results:

1) I have included network.h and it compiled without any errors or warnings so it looks like it passed
2) I have checked PCtoWii and found main section with that Init You mentioned, now things are going easier :)

So I guess first thing is to try define in some way server adress even static for now, port, channel and such things then trying to connect to it right?

Oh one more question a bit out of that problem but not worth of creating extra topic
Does someone know some command to make Home Button exit to HomeBrew Channel or Wii Menu? Not important which one of them will be, just to not have to do all things with Wii buttons :P
I have tried several from MLlib but none of them worked so far... heh same problem was long time ago with power off function for Nintendo DS :D

Thank You for advance and have a nice day/night

iSubaru

EDIT #1
Hahaha I wrote some code and made fatal code dump error xD now to track where...where...where...

EDIT #2
Looks like it was some background problem, I will mess with it later since I have white font :D
other problem is I can't overcome this:

main.c:51: error: 'sockaddr_in' undeclared (first use in this function)
main.c:52: error: request for member 'sin_port' in something not a structure or union

this is about this fragment:

sockaddr_in = sin;

sin.sin_port=htons(6667);

sin.sin_addr.s_addr=INADDR_ANY;

sin.sin_family=AF_INET;

I wonder what is a problem...in PCtoWii application source code it exists just with itself



Edited 2 time(s). Last edit at 12/06/2009 04:27AM by iSubaru.
Re: [Coding] IRC client, need some help
December 06, 2009 12:46PM
I don't know why it's just sockaddr_in in the PCToWii code, but there's no typedef for sockaddr, sockaddr_in and hostent, and probably some other structs.
Try using struct sockaddr_in instead.

struct sockaddr_in {
  u8 sin_len;
  u8 sin_family;
  u16 sin_port;
  struct in_addr sin_addr;
  s8 sin_zero[8];
};

If you don't have experience writing networking code, you might want to have a look at a BSD socket tutorial, like Beej's Guide to Network Programming.
Re: [Coding] IRC client, need some help
December 06, 2009 01:26PM
Yeah I don't have much experience, I had some tries but this time it's serious, with "thousand" of tutorials opened :D with Yours as well :)
I made some of this net_ commands and I got some responds from variables, most are zeros so probably it's ok (as man socket says) but net_accept turned -7 so it's probably some error... I will provide that fragments, maybe...no, not maybe...for sure I messed something up...maybe because of using many tutorials at once :D

let's see, I have this thing (many comments are there because of typing from them as examples and such things):
#include < MLlib.h >
#include < network.h >
#include "consolebg_png.h"
#include "cursor_png.h"
#include "font_png.h"
//#include <  sys/types.h >
//#include < sys/socket.h >

char *message;
char *buffer;


int main(int argc, char **argv) 
{
	ML_Init();
	ML_SplashScreen(); // You can delete this instruction, but please let it if you can :)
	ML_InitPad();
	net_init();
	
	ML_Image consolebgData;
	ML_Background consolebg; // we declare our background
	ML_LoadBackgroundFromBuffer(&consolebgData, &consolebg, consolebg_png, 0, 0); // we load the background
	ML_DrawBackground(&consolebg);

	ML_Image fontData;
	ML_Sprite font;
	ML_LoadSpriteFromBuffer(&fontData, &font, font_png, 100, 100);
	ML_InitTile(&font, 8, 8);	
	ML_SetSpriteScale(&font, 2, 2);

	ML_Image cursorData;
	ML_Sprite cursor;
	ML_LoadSpriteFromBuffer(&cursorData, &cursor, cursor_png, 100, 100);

	int Connect = net_init();
	ML_DrawSpriteText(&font, 16, 48, "Net_Init() in progress");

	/*while(Connect != 0)

	{

		printf("Net_Init() failed.\n");

		//waitfor(PAD_BUTTON_A);

	}*/
	ML_DrawSpriteText(&font, 16, 64, "Net_Init() successful");
	ML_DrawSpriteText(&font, 16, 80, "Net_Socket in progress");

	int netSocket = net_socket(AF_INET, SOCK_STREAM, 0);		//originally s32



	/*while(netSocket == INVALID_SOCKET)

	{

		printf("Net_Socket Initialization failed.\n");

		//waitfor(PAD_BUTTON_A);

	}*/


	ML_DrawSpriteText(&font, 16, 96, "Net_Socket successful");

	struct sockaddr_in sin;

	sin.sin_port=htons(6667);
	sin.sin_addr.s_addr = inet_addr("67.223.254.182");

	sin.sin_family=AF_INET;

	int c = net_connect(netSocket,(struct sockaddr *) &sin, sizeof(sin));
	//int c = net_connect(netSocket, &server_address, sizeof(sockaddr_in));
	net_bind(netSocket, (struct sockaddr *)&sin, sizeof(sin));

	/*message = fgets(buf, sizeof(buf), stdin);
	while (text != NULL) {
                send(sd, buf, strlen(buf), 0);
                n = recv(sd, buf, sizeof(buf), 0);
                write(1, buf, n);
                text = fgets(buf, sizeof(buf), stdin);
        }*/

	u32 len = sizeof(sin);

	int a = net_accept(netSocket, (struct sockaddr*)&sin, &len);
	int s = net_send(netSocket, message, strlen(message), 0);
	int r = net_recv(netSocket, buffer, sizeof(buffer), 0);


	while(1)
	{
		//if(Wiimote[0].Newpress.Home) ML_Exit();
		if(Wiimote[0].Newpress.Home) SYS_ResetSystem( SYS_POWEROFF, 0, 0 );
		
		ML_DrawBackground(&consolebg);

		net_listen(netSocket, 64);
		r = net_recv(netSocket, buffer, sizeof(buffer), 0);

		ML_DrawSpriteText(&font, 16, 112, "net_init status: %d", Connect);
		ML_DrawSpriteText(&font, 16, 128, "net_socket status: %d", netSocket);
		ML_DrawSpriteText(&font, 16, 144, "net_connect status: %d", c);
		ML_DrawSpriteText(&font, 16, 160, "net_send status: %d", s);
		ML_DrawSpriteText(&font, 16, 176, "net_recv status: %d", r);
		ML_DrawSpriteText(&font, 16, 192, "net_accept status: %d", a);

		ML_RotateSprite(&cursor, Wiimote[0].Orient.Roll, 0); 
		ML_Cursor(&cursor, 0);

		ML_Refresh();

	}
	

	return 0;

}

of course I had to make here space after < and before > to not make forum trying to parse it :D

Thank You for advance and sorry for mess in code

iSubaru
Re: [Coding] IRC client, need some help
December 11, 2009 01:16PM
I made some "corrections" but it's still not that :P Dolphin emu says that:
net_init - 0
net_socket - 469762048 (whatever it is)
net_connect - -106
net_send - 0
net_receive - 0
net_accepte - -12

The code is:

#include < MLlib.h >
#include < network.h >
#include "consolebg_png.h"
#include "cursor_png.h"
#include "font_png.h"

char *message;
char *buffer;
bool sw1 = 0;
bool sw2 = 0;
bool sw3 = 0;
bool sw4 = 0;
int Connect;
s32 netSocket;
int conn;
int c;
u32 len;
int a;
int s;
int r;


int main(int argc, char **argv) 
{
	ML_Init();
	ML_SplashScreen(); // You can delete this instruction, but please let it if you can :)
	ML_InitPad();
	
	ML_Image consolebgData;
	ML_Background consolebg; // we declare our background
	ML_LoadBackgroundFromBuffer(&consolebgData, &consolebg, consolebg_png, 0, 0); // we load the background
	ML_DrawBackground(&consolebg);

	ML_Image fontData;
	ML_Sprite font;
	ML_LoadSpriteFromBuffer(&fontData, &font, font_png, 100, 100);
	ML_InitTile(&font, 8, 8);	
	ML_SetSpriteScale(&font, 2, 2);

	ML_Image cursorData;
	ML_Sprite cursor;
	ML_LoadSpriteFromBuffer(&cursorData, &cursor, cursor_png, 100, 100);


	while(1)
	{
		ML_DrawBackground(&consolebg);

		if (sw1 == 0)
		{
			ML_DrawSpriteText(&font, 16, 48, "Net_Init() in progress");
			Connect = net_init();
			while(Connect != 0)

			{

				ML_DrawSpriteText(&font, 96, 48, "Net_Init() failed");

				if (Wiimote[0].Newpress.A)
				{
					ML_DrawSpriteText(&font, 16, 48, "                    ");
					ML_DrawSpriteText(&font, 96, 48, "                    ");
				}

			}
			ML_DrawSpriteText(&font, 16, 64, "Net_Init() successful");
			sw1 = 1;
		}

		if ((sw1 == 1) && (sw2 == 0))
		{
			ML_DrawSpriteText(&font, 16, 80, "Net_Socket in progress");

			netSocket = net_socket(AF_INET, SOCK_STREAM, 0);

			while(netSocket == INVALID_SOCKET)

			{

				ML_DrawSpriteText(&font, 96, 80, "Net_socket failed");

				if (Wiimote[0].Newpress.A)
				{
					ML_DrawSpriteText(&font, 16, 80, "                    ");
					ML_DrawSpriteText(&font, 96, 80, "                    ");
				}

			}
			ML_DrawSpriteText(&font, 16, 96, "Net_Socket successful");
			sw2 = 1;
		}

		if ((sw1 == 1) && (sw2 == 1))
		{
			struct sockaddr_in ircAddress;
			ircAddress.sin_family = AF_INET;
			ircAddress.sin_port = htons(6667);
			ircAddress.sin_addr.s_addr = inet_addr("67.223.254.182");
			sw3 = 1;
		}
			
		if ((sw3 == 1) && (sw4 == 0))
		{
			//if ((conn = net_connect(netSocket, (struct sockaddr *)&ircAddress, sizeof(struct sockaddr_in))) == -1)
			if ((c = net_connect(netSocket,(struct sockaddr *) &sin, sizeof(struct sockaddr_in))) == -1)
			{
				//msg about error
				sw4 = 0;
			}
			else 
			{
				net_bind(netSocket, (struct sockaddr *)&sin, sizeof(sin));
				(sw4 = 1);
			}
		}

		if (sw4 == 1)
		{
			len = sizeof(sin);
			a = net_accept(netSocket, (struct sockaddr*)&sin, &len);
			s = net_send(netSocket, message, strlen(message), 0);
			r = net_recv(netSocket, buffer, sizeof(buffer), 0);
		}

		net_listen(netSocket, 128);
		//r = net_recv(netSocket, buffer, sizeof(buffer), 0);

		ML_DrawSpriteText(&font, 16, 112, "net_init status: %d", Connect);
		ML_DrawSpriteText(&font, 16, 128, "net_socket status: %d", netSocket);
		ML_DrawSpriteText(&font, 16, 144, "net_connect status: %d", c);
		ML_DrawSpriteText(&font, 16, 160, "net_send status: %d", s);
		ML_DrawSpriteText(&font, 16, 176, "net_recv status: %d", r);
		ML_DrawSpriteText(&font, 16, 192, "net_accept status: %d", a);

		ML_RotateSprite(&cursor, Wiimote[0].Orient.Roll, 0); 
		ML_Cursor(&cursor, 0);
		//if(Wiimote[0].Newpress.Home) ML_Exit(); // doesn't work =_=
		if (Wiimote[0].Newpress.Home) SYS_ResetSystem( SYS_POWEROFF, 0, 0 ); // dunno if works
		ML_Refresh();

	}
	

	return 0;

}

I'm sure I made some mistakes but dunno what kind of and where...sockets are really annoying :P

Thank You for advance

iSubaru
Re: [Coding] IRC client, need some help
December 20, 2009 11:19AM
I don't know about your network problem, sorry... but for exiting the application, just use ML_Exit() et it will return to the loader (HBC). But you have to free all image data before if you want it to be fully working.
ML_DeleteImage(&imageData);

Hope it helps ;)

Oh and, if you want to shut down the Wii, use that :
ML_ShutdownWii();
for the moment . It's atm in fact SYS_ResetSystem(SYS_POWEROFF,0,0); but in next release that will be a nice exit with freeing and so on ;)
Sorry, only registered users may post in this forum.

Click here to login