Jump to content

Problem with connect/send/recv on TCP


DragonMinded

Recommended Posts

I have set up a simple way to request pages from my DS using TCP/IP. My connection is wep 64bit, and I am using autoconnect. When I connect to a remote server, it always comes back with a valid socket, where I then make my HTTP request. On occasion, the request comes back fine, and everything works great, but the vast majority of the time it hangs in the recieve loop, getting no data. I have set up a simple fake server on my PC, and the interesting thing is when it fails to recieve, it appears that the DS never made a connection with the server, even though there is a valid socket...

 

Is there a way I can test to make sure the socket I have currently is valid, and is there a better way than the below method for connecting via IP (more reliable?)

 

int wifiConnectIP(u32 ip, unsigned short port)
{
int sock = 0;
struct sockaddr_in tcp_sain;

sock = socket(AF_INET,SOCK_STREAM,0);

tcp_sain.sin_addr.s_addr = ip;
tcp_sain.sin_family = AF_INET;
tcp_sain.sin_port = htons(port);

connect(sock, (struct sockaddr *)&tcp_sain, sizeof(tcp_sain));
   
int i = 1;
ioctl(sock, FIONBIO, &i); // set non-blocking

return sock;
}

 

Also, as a side note, DNS on my DS seems very unreliable. The wifi lib test seems to do it fine, but in my code it locks up on the request 4 times out of 5, eventually going to black screens....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...