Announcement

Collapse
No announcement yet.

Only capable of receiving files/data that is less than equal to 1 kb

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Only capable of receiving files/data that is less than equal to 1 kb

    I am trying to send files from my PC to my PS2 over the internet using a router. Here is some of the code for the socket I have.
    Using ps2ip.

    Loading irx modules:
    Code:
    int LoadIRX()
    {
    
    	int a;
    
    	scr_printf("	Beginning initialization!\n");
    	
    	a = SifExecModuleBuffer(&POWEROFF_IRX, size_POWEROFF_IRX, 0, NULL, &a);
    	if (a < 0 )
    	{
            scr_printf("	Could not load POWEROFF.IRX! %d\n", a);
    	return -1;
    	}
    
    	scr_printf("	Loaded POWEROFF.IRX!\n");
    
    	a = SifExecModuleBuffer(&PS2DEV9_IRX, size_PS2DEV9_IRX, 0, NULL, &a);
       	if (a < 0 )
    	{
            scr_printf("	Could not load PS2DEV9.IRX! %d\n", a);
    	return -1;
    	}
    
    	scr_printf("	Loaded PS2DEV9.IRX!\n");
    
    	a = SifExecModuleBuffer(&PS2IP_IRX, size_PS2IP_IRX, 0, NULL, &a);
    	if (a < 0 )
    	{
            scr_printf("	Could not load PS2IP.IRX!\n %d", a);
    	return -1;
    	}
    
    	scr_printf("	Loaded PS2IP.IRX!\n");
    
    	a = SifExecModuleBuffer(&DNS_IRX, size_DNS_IRX, 0, NULL, &a);
    	if (a < 0)
    	{
            scr_printf("	Could not load DNS.IRX! %d\n", a);
    	return -1;
    	}
    
    	scr_printf("	Loaded DNS.IRX!\n");
    
    	a = SifExecModuleBuffer(&PS2IPS_IRX, size_PS2IPS_IRX, 0, NULL, &a);
    	if (a < 0)
    	{
            scr_printf("	Could not load PS2IPS.IRX! %d\n", a);
    	return -1;
    	}
    
    	scr_printf("	Loaded PS2IPS.IRX!\n");
    
            //Taken from http://forums.ps2dev.org/viewtopic.php?t=11553&highlight=ps2ipinit
            //Credit to methos3
    	char *IP = ReadIP();
    	char *NM = ReadNM();
    	char *GW = ReadGW();
        	char *args = malloc(strlen(IP) + strlen(NM) + strlen(GW) + 3); 
        	int b = 0; 
    	memset(&b, 0, sizeof(b + 1));
    	strcpy(&args[b], IP); b+=strlen(IP)+1; 
    	strcpy(&args[b], NM); b+=strlen(NM)+1; 
    	strcpy(&args[b], GW); b+=strlen(GW)+1; 
    	a = SifExecModuleBuffer(&SMAP_IRX, size_SMAP_IRX, b, args, &a);
    	if (a < 0)
    	{
            scr_printf("	Could not load SMAP.IRX! %d\n", a);
    	return -1;
    	} 
    
    	scr_printf("	Loaded SMAP.IRX!\n");
    	
    	scr_printf("	Loaded irx modules\n");
    
    	a = ps2ip_init();
    	if (a < 0)
    	{
    	scr_printf("	Could not initialize ps2ip %d\n", a);
    	return -1;
    	}
    
    	scr_printf("	Initialized ps2ip!\n");
    
    	scr_clear();
    	
    	return 0;
    
    }
    Snippet of server initialization:

    Code:
    sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP );
    
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(2345);
    bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr);
    
    // Using send and recv, n is declared as 0
    // newsockfd is created when the connection between the PC and the PS2 is made
    // Yes it says 1024, but that is because I haven't gotten it to go past 1 kb
    // If I could, I would increase it, so right now I just go with it
    char buffer[1024];
    n = recv(newsockfd, buffer, 1024, 0);
    I can somewhat get past the limit by following the first recv with another recv, but there is packet loss. If I raise the recv size to something higher than 1024, it just follows the first 1024 bytes with 0x00.

    So anyway can I recv data that has a size greater than 1 kb?
    Thanks.

  • #2
    Loop it. Append next parts to stored first part until finished and you will have the whole. In your code the value of 'n' will be greater than 0 if there is data being received.
    Last edited by Gtlcpimp; 10-08-2012, 03:24:53 PM.

    Comment


    • #3
      Actually recv doesn't return 0 when it isn't receiving data. Unless I set the socket to non block with setsockopt. Which I have no idea how to use on the PS2.

      http://psp.jim.sh/svn/filedetails.ph...kets.h&rev=208

      Comment


      • #4
        The available libraries will either return a negative value if nothing is being received or it will hang in a loop waiting for inbound traffic (depending on which library revision / modifications you have). Loop it, append it, problem solved.

        Comment


        • #5
          Did something like this

          Code:
          int y = 0;
          char *buf[3072];
          buf = malloc(3072);
          
          do {
          	n = recv(newsockfd, buffer, 1, 0);
          	memcpy(buf + y, buffer, 1);
          	y++;
          	if (n <= 0) { scr_printf(" %d:%d", y, n); }				
          } while (n > 0);
          Never returns zero. Just waits on recv() for incoming packets. Then n returns the size in bytes, which loops back if it is greater than 0 (100% of the time) and gets me nowhere.

          Got this to work. PC sends byte size then data.

          Code:
          char *buf[1], *buf2[5];
          int y = 0;
          		
          n = recv(newsockfd, buf2, 4, 0);
          buf2[strlen((char*)buf2) + 1] = '\0';
          int size = atoi((char*)buf2);
          scr_printf("	Receiving size of (%d)\n", size);
          		
          while (y < size) {
          n = recv(newsockfd, buf, 1, 0);
          memcpy(buffer + y, buf, 1);
          y++;
          }
          That seems to works pretty well.

          Thanks for the help.
          Last edited by dnawrkshp; 10-10-2012, 12:33:25 AM.

          Comment

          Working...
          X