forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceNetInetConnect not returning

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
poison



Joined: 14 Dec 2006
Posts: 17

PostPosted: Mon Apr 07, 2008 11:54 pm    Post subject: sceNetInetConnect not returning Reply with quote

I wrote a user mode prx to activate wifi device, and connect to a socket server, sceNetInetSocket and sceNetInetSetsockopt just work fine, but when I launch sceNetInetConnect, it never return but not crashing.
Here is a piece of my code:

Code:

PSP_MODULE_INFO( "wifiuser", 0, 1, 0 );
PSP_MAIN_THREAD_ATTR( PSP_THREAD_ATTR_USER );

......

int wifiInit( const char * ip_addr, int port )
{
   struct sockaddr_in addr;
   int flag = 1, cmd, res;
   
   log( "ip %s port %d\n", ip_addr, port );
   if ( connectApctl( 1 ) < 0 )
   {
      return -1;
   }

   sock_server = sceNetInetSocket( PF_INET, SOCK_STREAM, 0 );
   if ( sock_server < 0 )
   {
      log( "Error create sock connection\n" );
      return -1;
   }
   log( "create sock %08x\n", sock_server );
   int ret = sceNetInetSetsockopt( sock_server, SOL_TCP, TCP_NODELAY, &flag, sizeof( flag ) );
   log ( "ret %08x\n", ret );
   addr.sin_family = AF_INET;
    addr.sin_port = htons( 7513 );
    addr.sin_addr.s_addr = sceNetInetInetAddr( ip_addr );
   log( "ip address %08x\n", ( unsigned int )addr.sin_addr.s_addr );
   
   ret = sceNetInetConnect( sock_server, ( struct sockaddr * )&addr, sizeof( addr ) );
   log ( "ret %08x\n", ret );
   if ( ret < 0 )
   {
      log( "Error connect to sock %08x\n", sock_server );
      return -1;
   }
}

......

int module_start( SceSize args, void *argp )
{
   thid = sceKernelCreateThread( "wifhost_thread", main_thread, 0x20, 0x10000, PSP_THREAD_ATTR_USER, NULL );
   if( thid >= 0 )
      sceKernelStartThread( thid, 0, 0 );
   return 0;
}

int module_stop( SceSize args, void *argp )
{
   return 0;
}


log.txt:
Code:

connection state 0
connection state 2
connection state 3
connection state 4
ip 192.168.1.27 port 7513
create sock 0000000b
ret 00000000
ip address 1b01a8c0


As the log.txt shown, sceNetInetConnect keep running...
I had a lots modification try on the sockaddr_in structure and the thread stack size, but no result, is it just looping in sceNetInetConnect? or I passed something wrong? it almost drove me mad..
Back to top
View user's profile Send private message
zmast



Joined: 10 Apr 2008
Posts: 3

PostPosted: Fri Apr 11, 2008 2:43 am    Post subject: Reply with quote

I'm not sure I'll be able to help you but I'll tell you what i know.

First, sceNetInetConnect is by default blocking. This means that it won't return until the connection is enstabilished.

If this is your case then something may be wrong in your network setup.
So you could think about firewalls etc, but i assume you already tried to disable them and verified that there is a service listening at port 7513 at 192.168.1.27.
One other problem may be in the AP connection, if I'm not wrong i read somewhere that old firmwares could only connect to profiles using static IP addresses. Personally i'm using DHCP on 3.90 M33 and it is ok.
So i would try to see if i'm connected to AP with a valid IP.
You can check this using this block of code taken from net.c in sdk samples:
Code:

         // connected, get my IPADDR and run test
         char szMyIPAddr[32];
         if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
            strcpy(szMyIPAddr, "unknown IP address");


I don't see strange things in your code, it should be okay, any way this is my function which i know for sure is perfectly working (it also supports timeout on connection).
Try it if you want to.

Code:

int netutil_TcpConnect(unsigned long RemoteIp, unsigned short RemotePort)
{
   int sock;
   struct sockaddr_in Addr;
   int err;
   int NoBlock;
   int ElapsedTime = 0;

   sock = sceNetInetSocket(PF_INET, SOCK_STREAM, 0);
   if(sock < 0)
   {
      return NETUTIL_ERR_INTERNAL;
   }

   Addr.sin_family = AF_INET;
   Addr.sin_port = htons(RemotePort);
   Addr.sin_addr.s_addr = htonl(RemoteIp);
   
   NoBlock = 1;
   sceNetInetSetsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &NoBlock, sizeof(NoBlock));

   err = sceNetInetConnect(sock, (struct sockaddr *)(&Addr), sizeof(Addr));
   if(err == 0)    //Connesso al primo compo? che culo!
   {
      NoBlock = 0;
      sceNetInetSetsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &NoBlock, sizeof(NoBlock));
      return sock;
   }
   else if(err == -1 && sceNetInetGetErrno() == EINPROGRESS)
   {
      do
      {
         err = sceNetInetConnect(sock, (struct sockaddr *)(&Addr), sizeof(Addr));
         if(err == 0 || (err == -1 && sceNetInetGetErrno() == EISCONN)) //Connesso! :)
         {
            NoBlock = 0;
            sceNetInetSetsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &NoBlock, sizeof(NoBlock));
            return sock;
         }
         else
         {
            sceKernelDelayThread(50*1000); // 50ms
            ElapsedTime += 50;
         }
      } while(ElapsedTime < NETUTIL_TCPCONNECT_TIMEOUT);
       
      NoBlock = 0;
      sceNetInetSetsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &NoBlock, sizeof(NoBlock));
      sceNetInetClose(sock);
      return NETUTIL_ERR_TIMEOUT;
   }
   
   NoBlock = 0;
   sceNetInetSetsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &NoBlock, sizeof(NoBlock));
   sceNetInetClose(sock);
   return NETUTIL_ERR_INTERNAL;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group