net_socket problem

support for the powerpc toolchain
Post Reply
acidice333
Posts: 5
Joined: Thu Sep 02, 2010 2:28 am

net_socket problem

Post by acidice333 » Tue Sep 07, 2010 2:59 am

I'm trying to open a socket with SOCK_DGRAM UDP but its returning -1. When I change this to SOCK_STREAM TCP it opens a socket fine. Is UDP broken?

Code: Select all

s32 connection = net_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (connection < 0) GRRLIB_Printf(95, 25, tex_BMfont5, GRRLIB_LIME, 1, "could not open socket");
else GRRLIB_Printf(95,25,tex_BMfont5,GRRLIB_LIME,1,"socket opened");

User avatar
Izhido
Posts: 107
Joined: Fri Oct 19, 2007 10:57 pm
Location: Costa Rica
Contact:

Re: net_socket problem

Post by Izhido » Tue Sep 07, 2010 2:29 pm

Try this:

Code: Select all

s32 connection = net_socket (PF_INET, SOCK_DGRAM, IPPROTO_IP)
To be honest, I don't actually know why this works, and yours not. Yet, most sources I've seen use those parameters. Give it a try.

acidice333
Posts: 5
Joined: Thu Sep 02, 2010 2:28 am

Re: net_socket problem

Post by acidice333 » Tue Sep 07, 2010 8:33 pm

Ok now I get connection = 0 with this.

Code: Select all

s32 connection = net_socket (PF_INET, SOCK_DGRAM, IPPROTO_IP)
From looking at network.h it looks as tho PF_INET and AF_INET are the same (one defines into the other)

Code: Select all

#define AF_UNSPEC			0
#define AF_INET				2
#define PF_INET				AF_INET
#define PF_UNSPEC			AF_UNSPEC
Here is the network code of my program ( I decided to rewrite it )

Code: Select all

//---------------------------------------------------------------------------------
void *httpd (void *arg) {
//---------------------------------------------------------------------------------

	s32 sock, csock;
	int ret;
	struct sockaddr_in server;
	char temp[1026];
	static int hits=0;
	
	sock = net_socket (PF_INET, SOCK_DGRAM, IPPROTO_IP);

	if (sock == INVALID_SOCKET) {
      printf ("Cannot create a socket!\n");
    } else {
		printf("socket = %d \n", sock); // SHOWS '0'

		memset (&server, 0, sizeof (server));

		server.sin_family = PF_INET;
		server.sin_port = htons (5555);
		server.sin_addr.s_addr = inet_addr("10.0.0.145");
		
	int n;
	char buf[1024];
	sprintf(buf,"wii connect :)");
	//n = net_sendto(sock,buf,sizeof(buf),0,(struct sockaddr*)&server,sizeof(struct sockaddr));
	n = net_send(sock,buf,sizeof(buf),0);
	if (n<0) {
		printf("could not connect (%d) \n", n);
	} else {
		printf("connected! (bytes: %d) \n",n);
	}
		
	}
	return NULL;
}
sock = 0
and then when it tries to send, it doesnt work (n = -121)
I've created a client app on the computer and it does infact work Ive even thrown it onto one of my internet servers and tried to connect to it using my computer client and it works. This wii is giving me problems :( I could use TCP but I don't want to!

acidice333
Posts: 5
Joined: Thu Sep 02, 2010 2:28 am

Re: net_socket problem

Post by acidice333 » Tue Sep 07, 2010 10:21 pm

Ok looks like I've figured out.

I needed to set...

Code: Select all

server.sin_len = 8; // without this set to 8? it wont work (returns -22 on send)
And then use..

Code: Select all

n = net_sendto(sock,buf,sizeof(buf),0,(struct sockaddr*)&server,server.sin_len);
On net_sendto before `server.sin_len` it was `sizeof(struct sockaddr)` which was `16`.
sendto() works now with 8, but send() returns -121

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: net_socket problem

Post by WinterMute » Wed Sep 08, 2010 11:58 am

A lot of these problems are related to the differences between Nintendo's tcp/ip stack and the lwip stack we were using on gamecube. There are a few places where we've overridden parameters before passing them to IOS but obviously there are still a few places in there where corrections are needed.

Something I'd really like to do for both gamecube and wii is provide standard headers for the network functions rather than all the custom stuff we have right now. It would make it much easier to port code and not run foul oddities like this. As usual, time is in short supply so if some enterprising soul had a look at doing that then a patch would be greatly appreciated :wink:
Help keep devkitPro toolchains free, Donate today

Personal Blog

ccfreak2k
Posts: 14
Joined: Sat Mar 06, 2010 1:11 pm

Re: net_socket problem

Post by ccfreak2k » Wed Sep 15, 2010 1:26 am

No promises for Wii, but I could take a stab at "standardizing" the GameCube part if there's a list of things that are custom in this right now.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests