Welcome! Log In Create A New Profile

Advanced

network programming problem

Posted by g_man 
network programming problem
October 17, 2010 09:28PM
I am just getting started with network programming, and I need a little help. I have made a successful client and server on windows, but I can't get a client on the wii to connect to my windows client. I know my windows server works because I have gotten it to send and recieve messages from other computers in my house running different OS's. I have double checked my port and Ip numbers, but I was wondering if a person with more experience could help me find my problem.
Thank you
#include stdio.h
#include stdlib.h
#include gccore.h
#include wiiuse/wpad.h
#include unistd.h
#include network.h

#define	PORT		12432
#define SERVERIP	"192.168.1.5"

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

void initialization(){
	VIDEO_Init();
	WPAD_Init();
	rmode = VIDEO_GetPreferredMode(NULL);
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	printf("\x1b[2;0H");
}

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	initialization();
	
    int mySocket;
	struct sockaddr_in mySockaddr;
	char buffer[256];
	char *msg = "Hello from the WII!!!\0";
	
	
	mySocket = net_socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	mySockaddr.sin_family = AF_INET;
	mySockaddr.sin_port = PORT;
	inet_aton(SERVERIP,&mySockaddr.sin_addr);
	while(net_connect(mySocket,(struct sockaddr*)&mySockaddr,sizeof(mySockaddr))==-1);
	printf("connected!!!\n");
	net_recv(mySocket,buffer,sizeof(buffer),0);
	printf("%s\n",buffer);
	net_send(mySocket,msg,strlen(msg),0);


	while(1) {


		WPAD_ScanPads();

		u32 pressed = WPAD_ButtonsDown(0);

		if ( pressed & WPAD_BUTTON_HOME ) exit(0);


		VIDEO_WaitVSync();
	}

	return 0;
}

Re: network programming problem
October 18, 2010 01:20AM
You didn't init network, see libogc examples(devices/network/sockettest).
Re: network programming problem
October 18, 2010 05:53AM
ok, but that still doesn't work. I had a look at sockettest, but it didn't help.
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	initialization();
	net_init();	
	
    int mySocket;
	struct sockaddr_in mySockaddr;
	char buffer[256];
	char *msg = "Hello from the WII!!!\0";
	char localip[16] = {0};
	char gateway[16] = {0};
	char netmask[16] = {0};
	
	memset(buffer,0,256);
	printf("here is buffer: %s\nThere it i\n",buffer);
	if(if_config(localip,netmask,gateway,TRUE)!=-1){
		printf ("network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
		
	
		mySocket = net_socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
		mySockaddr.sin_family = AF_INET;
		mySockaddr.sin_port = PORT;
		inet_aton(SERVERIP,&mySockaddr.sin_addr);
		while(net_connect(mySocket,(struct sockaddr*)&mySockaddr,sizeof(mySockaddr))==-1);
		printf("connected!!!\n");
		net_recv(mySocket,buffer,sizeof(buffer),0);
		printf("%s\n",buffer);
		net_send(mySocket,msg,strlen(msg),0);
	} else {
		printf ("network configuration failed!\n");
	}


	while(1) {


		WPAD_ScanPads();

		u32 pressed = WPAD_ButtonsDown(0);

		if ( pressed & WPAD_BUTTON_HOME ) exit(0);


		VIDEO_WaitVSync();
	}

	return 0;
}

Re: network programming problem
October 18, 2010 09:58PM
net_socket doesn't support IPPROTO_TCP, only IPPROTO_IP.(It returns an error when you try TCP like that btw.)
Re: network programming problem
October 19, 2010 07:08AM
Ok, I replaced it and nothing changed.
EDIT: Nevermind, I had the wrong IP, everything works, thanks.



Edited 1 time(s). Last edit at 10/19/2010 07:13AM by g_man.
Sorry, only registered users may post in this forum.

Click here to login