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 

bind failed

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



Joined: 17 Oct 2005
Posts: 12

PostPosted: Mon Oct 17, 2005 7:56 am    Post subject: bind failed Reply with quote

Hi

I don't know whether this is problem is PSP or network related but it here it goes: I have a domotica system which is controlled by a dsp over a tcp/ip network. The dsp is always listening for a connection, a host (my pc mostly) connects to it, and after disconnecting the host the dsp starts listening again.
I ported the host to my PSP with the sdk, so now I can control lights etc in my room with the PSP, very nice. But after disconnecting the host on the PSP and putting it off, the dsp says "failed bind: address already in use" when it starts listening again..
It looks like the PSP connection hasn't disconnected although I call all these functions when closing:
sceNetApctlTerm();
sceNetResolverTerm();
sceNetInetTerm();
sceNetTerm();

anyone has an idea of what I can do more to let it disconnect properly?

Peace!
Back to top
View user's profile Send private message
liquid8d



Joined: 30 Jun 2005
Posts: 66

PostPosted: Mon Oct 17, 2005 11:28 am    Post subject: Reply with quote

most likely you aren't closing the sockets in use.. try:

sceNetInetClose(socketnum);

LiQuiD8d
Back to top
View user's profile Send private message AIM Address
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Mon Oct 17, 2005 3:33 pm    Post subject: Reply with quote

If you are calling 'Close' and still getting the problem, it may be necessary to continue calling recv on the socket until it gracefully disconnects (either will turn a 0, or will return an error) before actually quitting the application.

or... you just just call sceKernelDelayThread(2000); ;) but honestly, receiving all of your data is the best way, so you can ensure you didnt miss any bytes in the stream.
Back to top
View user's profile Send private message AIM Address MSN Messenger
stinos



Joined: 17 Oct 2005
Posts: 12

PostPosted: Mon Oct 17, 2005 5:55 pm    Post subject: Reply with quote

@liquid8d: I forgot to tell but I'm also calling sceNetInetClose and sceInetApctlDisconnect
@Cyberbill: I'll try the approach of calling recv a number of times although tonight, sounds like a good idea!
Back to top
View user's profile Send private message
stinos



Joined: 17 Oct 2005
Posts: 12

PostPosted: Tue Oct 18, 2005 10:56 pm    Post subject: Reply with quote

I tried calling rcv in a while loop until it returns 0 or < 0, but it returns immedeately wihtout receiving anything and the problem remains :-[
Maybe someone can post a bit of source code displaying how they use the tcp communication so I can see how it differs from what I'm doing??
Back to top
View user's profile Send private message
PspPet



Joined: 30 Mar 2005
Posts: 210

PostPosted: Wed Oct 19, 2005 12:01 am    Post subject: Reply with quote

> If you are calling 'Close' and still getting the problem, ...
also try calling "sceNetInetShutdown" before closing (for TCP/IP connection oriented sockets).
I haven't tested the "how" parameter (but it should be "2" for shutdown both send and receive)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stinos



Joined: 17 Oct 2005
Posts: 12

PostPosted: Thu Oct 20, 2005 7:24 am    Post subject: Reply with quote

the shutdown trick didn't do it.. pretty clueless now ;-]
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Thu Oct 20, 2005 7:36 am    Post subject: Reply with quote

okay, Id really recomend taking a look at this with ethereal or some other TCP/IP packet sniffer. THey can tell you a lot about whats going on with the connection, so you can verify whether or not its actually closing.

-Bill
Back to top
View user's profile Send private message AIM Address MSN Messenger
stinos



Joined: 17 Oct 2005
Posts: 12

PostPosted: Sun Oct 23, 2005 4:10 am    Post subject: Reply with quote

ok I finally found it.. Appearentely I was calling nlhTerm() to quickly after sceInetClose( socket ) resulting in a lost [FIN,ACK] packet.
Putting a delay between the two didn't help, probabely because a deley just freezes the thread. So I made a seperate 'disconnect command', first call it from the gui on a keypress, close the socket, return control to the gui and then on the 'home' button call the nlhTerm etc.
Anyway, it works like a charm now, thanks for all the help!!
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Oct 23, 2005 5:33 am    Post subject: Reply with quote

Thats very strange that you cant do a delay.

Oh, I think I know why.
err = sceNetApctlInit(0x1000, 0x42);

Change 0x42 to something much lower. 0x10 perhaps. And change:

err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);

to have the two 0x20s be something more like 0x12.

That will ensure that your network thread is much higher priority than your main thread, so that network stuff will actually happen in the background. Then just do a sleep call for a few miliseconds and see what happens.
Back to top
View user's profile Send private message AIM Address MSN Messenger
stinos



Joined: 17 Oct 2005
Posts: 12

PostPosted: Tue Oct 25, 2005 5:18 pm    Post subject: Reply with quote

^ this seems to be working to, thanks for the info!
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