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 

Wifi - Sockets Problems

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



Joined: 09 Jul 2009
Posts: 31

PostPosted: Thu Jul 30, 2009 4:24 am    Post subject: Wifi - Sockets Problems Reply with quote

Hi, I've some problems with sockets:

PSP
Code:
char string[10];
sprintf(string,"PALIB_HI");

struct sockaddr_in i_addr;
i_addr.sin_family = AF_INET;
i_addr.sin_port = htons(6666);
i_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
int i=0;

ClientSockSend=socket(AF_INET, SOCK_DGRAM, 0);
         

setsockopt(ClientSockSend,SOL_SOCKET,SO_BROADCAST,&optval,sizeof(char));


while(1)
{

     sendto(ClientSockSend,string,10,0, (struct sockaddr *) &i_addr, sizeof(i_addr));
         
     printf("\nSending: %d , %s",i,string);
     i++;
     sceDisplayWaitVblankStart();
}


PC
Code:

struct sockaddr_in i_addr;
i_addr.sin_family = AF_INET;
i_addr.sin_port = htons(6666);
i_addr.sin_addr.s_addr = htonl(INADDR_ANY);

ServerSockListen=socket(AF_INET, SOCK_DGRAM, 0);
      
bind(ServerSockListen, (struct sockaddr *) &i_addr, sizeof(i_addr));

      

int i=0;
char buffer[10];
memset(buffer,'\0',10);
while(1)
{
         
   int size=sizeof(struct sockaddr);

         
   int rc=0;
   iprintf("Waiting: ",i,"");
   int ix=0;
   while(1)
   {
            
      rc=recvfrom(ServerSockListen,buffer,10,0, (struct sockaddr *) &i_addr, &size);
            
      if(rc==-1) break;


      iprintf("Buffer: ",buffer);
      if(buffer[0]=='P' && buffer[1]=='A')
      {
         //iprintf("Received:  ",buffer);
      }
         
   }
   i++;
   swiWaitForVBlank();
}



The PSP sends a string and the PC should receive it, but it doesn't receive anything... (Broadcast)

If I use the same code for the PC to send and the PSP to receive, it works...

Do you know why ??
Back to top
View user's profile Send private message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Thu Jul 30, 2009 5:06 am    Post subject: Reply with quote

Are you sure your psp is connected to an access point?
Are you using the right IP addresses?
_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
DarkShadow44



Joined: 09 Jul 2009
Posts: 31

PostPosted: Thu Jul 30, 2009 6:17 am    Post subject: Reply with quote

1) --> "If I use the same code for the PC to send and the PSP to receive, it works..."

The PSP can receive the messages of the PC

2) I use Auto configured connections...

I use the "netdialog" sample it is the easiest (and best) for wifi connections.


P.S. I tried it with PC <-> PC and DS <-> PC, that works too :-(
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Aug 11, 2009 12:53 pm    Post subject: Reply with quote

Are you in infrastructure mode or ad-hoc mode?
Getting broadcast to work with a wireless network could be tricky.
With an AP, you can send a directed IP-broadcast packet to the router which can then do a MAC-broadcast on the local network, but with ad-hoc, you need to do a broadcast at the MAC layer, and the PSP might not automatically detect and support that.

In fact it may not support broadcast at all -- it might just refuse to route outgoing packets destined for 255.255.255.255.
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Aug 12, 2009 1:44 pm    Post subject: Reply with quote

Most routers will drop broadcast packets. If he's in infrastructure mode then just sending to the subnet's broadcast address is sufficient. No need to send to the router's address. WLAN is transparent usually to the physical lan connected to the AP.

E.g. Send to 192.168.1.255 (broadcast address) if your subnet is 192.168.1.0/24 (IP 192.168.1.xxx & Subnet Mask 255.255.255.0)

Try this manually first in case something is broken with SO_BROADCAST.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Aug 13, 2009 1:29 am    Post subject: Reply with quote

Two things I learned when doing networking on Doom for PSP: first, you need to do explicit waiting in places to give the network threads time to run; remember that the PSP uses cooperative multitasking, and if you don't give up time, the network threads won't run. Second, you use IP addresses directly in your packets. As Torch mentioned, broadcast packets don't seem to work well, and it's the router's responsibility to direct packets to the proper computer based on the IP address/port. If everything has the same external IP address, be sure to set your router's port forwarding to the correct local IP.
Back to top
View user's profile Send private message AIM Address
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Thu Aug 13, 2009 2:11 am    Post subject: Reply with quote

From the looks of things he's got all devices on the same subnet. Sending a packet to the subnet's broadcast address will work in all cases but only devices on the same subnet with no router inbetween will receive it (LAN/WLAN). There is NO way a broadcast will work over the internet unless you have UDP tunnelling software like Gamer's Internet Tunnel which sniffs and forwards all LAN packets and replaces the header at both sending and receiving end according to the local subnet. From address is replaced with the sender's external IP etc. Once a client identifies a server with a broadcast, it tries to conntect to the IP the reply came from and ends up connecting to the external IP of the server on the other LAN across the internet (port forwarding for the actual connection should be done).

If you're trying to list servers over the internet, then thats why they have master servers with static addresses :)
Back to top
View user's profile Send private message
DarkShadow44



Joined: 09 Jul 2009
Posts: 31

PostPosted: Sat Aug 15, 2009 1:54 am    Post subject: Reply with quote

First, thanks for the replies.

I tried the Broadcasts PSP <-> PC ; PSP --> PC didn't work.

But the same code worked with the DS...


But why doesn't it work over the internet ?

I can't use master servers, because I don't want to pay anything (and I don't know how to write master servers for many clients...)

I want to create a little Game, that searches for hosts and then you can join. How could I do this (without having to pay for something) ???
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sat Aug 15, 2009 9:43 am    Post subject: Reply with quote

DarkShadow44 wrote:
First, thanks for the replies.

I tried the Broadcasts PSP <-> PC ; PSP --> PC didn't work.

But the same code worked with the DS...


But why doesn't it work over the internet ?

I can't use master servers, because I don't want to pay anything (and I don't know how to write master servers for many clients...)

I want to create a little Game, that searches for hosts and then you can join. How could I do this (without having to pay for something) ???


Did you try using the broadcast address directly?? Ex: Send to 192.168.1.255 if your IPs are 192.168.1.1....192.168.1.2...192.168.1.254 etc.

A broadcast is sent only to the same subnet as the broadcast address you used. Hence it won't work on the internet. There is no way to find games on the internet without a static master server.
Back to top
View user's profile Send private message
DarkShadow44



Joined: 09 Jul 2009
Posts: 31

PostPosted: Sat Aug 15, 2009 11:59 pm    Post subject: Reply with quote

1) Do you know a page, where I could create a master server for free ?

2a)Or could I use a MySQL-Database on a free homepage ?
2b) Can I access such a Database with the PSP ?
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 16, 2009 1:12 am    Post subject: Reply with quote

The ideal master server would be a realtime application that receives notifications from a game server as soon as the game server has started and stores its IP. It should poll all the servers periodically to check if they are still online and remove dead servers. This would function at the application layer hence you'd need to communicate between the game server and master server using your own protocol/magicwords and stuff.

You could pull this off with a Perl script that listens for connections but most free webhosts won't let you run a realtime script. Most of them won't even let you receive or make connections from the script.

So you'd just need to use a Perl/PHP script that receives the server info through a standard HTTP request and stores the information in a SQL database. Clients can query the list of servers either directly from the database (if the webhost allows) or through a Perl/PHP script via HTTP.

You'll need to manually purge dead servers from the database using an external script/application on your PC.

You need to have some basic server side scripting knowledge to get this working. You can probably get away with using the Sony modules for HTTP requests from the PSP.
Back to top
View user's profile Send private message
DarkShadow44



Joined: 09 Jul 2009
Posts: 31

PostPosted: Sun Aug 16, 2009 7:47 am    Post subject: Reply with quote

Can you say me, how a simple PHP script must be for getting/writing all hosts to the Database ?

Dead servers wouldn't be a problem, or is it to much if the PSP creates checks if a connection to each server is possible ? (for example with ping?)

Would be nice if you can help me, I know that it isn't easy...

I only want a very basic script for "talking" with the PSP or Database.

P.S.

Would this or that be possible ?

Sorry that they are not english ^^

2) Do you know if this would be really "free" ?
3) What does "8 FTP-Accounts" mean, can I upload 8 Files ??
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 16, 2009 12:15 pm    Post subject: Reply with quote

DarkShadow44 wrote:

3) What does "8 FTP-Accounts" mean, can I upload 8 Files ??


You've got a LOT to learn before you can attempt this...
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