| View previous topic :: View next topic |
| Author |
Message |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Mon Oct 17, 2005 7:56 am Post subject: bind failed |
|
|
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 |
|
 |
liquid8d
Joined: 30 Jun 2005 Posts: 66
|
Posted: Mon Oct 17, 2005 11:28 am Post subject: |
|
|
most likely you aren't closing the sockets in use.. try:
sceNetInetClose(socketnum);
LiQuiD8d |
|
| Back to top |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Mon Oct 17, 2005 3:33 pm Post subject: |
|
|
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 |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Mon Oct 17, 2005 5:55 pm Post subject: |
|
|
@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 |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Tue Oct 18, 2005 10:56 pm Post subject: |
|
|
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 |
|
 |
PspPet
Joined: 30 Mar 2005 Posts: 210
|
Posted: Wed Oct 19, 2005 12:01 am Post subject: |
|
|
> 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 |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Thu Oct 20, 2005 7:24 am Post subject: |
|
|
| the shutdown trick didn't do it.. pretty clueless now ;-] |
|
| Back to top |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Thu Oct 20, 2005 7:36 am Post subject: |
|
|
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 |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Sun Oct 23, 2005 4:10 am Post subject: |
|
|
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 |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Sun Oct 23, 2005 5:33 am Post subject: |
|
|
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 |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Tue Oct 25, 2005 5:18 pm Post subject: |
|
|
| ^ this seems to be working to, thanks for the info! |
|
| Back to top |
|
 |
|