bind failed

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

bind failed

Post by stinos »

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!
liquid8d
Posts: 66
Joined: Thu Jun 30, 2005 6:29 am

Post by liquid8d »

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

sceNetInetClose(socketnum);

LiQuiD8d
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

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.
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

@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!
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

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??
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

> 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)
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

the shutdown trick didn't do it.. pretty clueless now ;-]
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

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
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

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!!
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

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.
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

^ this seems to be working to, thanks for the info!
Post Reply