network programming problem October 17, 2010 09:28PM | Registered: 15 years ago Posts: 444 |
#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 | Registered: 15 years ago Posts: 188 |
Re: network programming problem October 18, 2010 05:53AM | Registered: 15 years ago Posts: 444 |
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 | Registered: 15 years ago Posts: 188 |
Re: network programming problem October 19, 2010 07:08AM | Registered: 15 years ago Posts: 444 |