I'm having a couple of problems with my sockets on the Palm. These problems
may well be with my limited understanding of sockets - if so, please point
me to a good online socket reference / tutorial. Or they could be Palm
issues...
Problem 1
The first problem is with NetLibSelect(). As I understand it, this should
allow me to block until either some user input is received, or until a
socket has some activity on it.
So, what I do is set up a listen socket to wait for connections from remote
clients, and then use select to wait for either a client to connect, or some
user input to happen. The user input side is fine, only when the user does
something does select report a user event, and I can then do the normal
event loop stuff to process.
However, the listen socket always reports that there's something to do on
the socket, even when there isn't. Even if I use a 'fake' SLIP connection
on the emulator (without NetLib redirection) select always reports that
there's something to do on the socket. (I've also tested on a real Palm and
it does the same)
So... am I understanding NetLibSelect properly? I was expecting to only get
a positive response for the listen socket if someone was trying to connect
to it. However, I'm suspicious that it actually returns positive for the
socket if it's _ready_ to accept, rather than there being someone trying to
connect. I'd appreciate it if someone could set me straight on this.
If this is the case, how to I handle both network and user activity on the
Palm, given I don't have threads? Currently I use select to work out who's
ready, and then process them. The UI is fine and gets processed when
there's an event to process, but the Network is always ready. So what I do
is a NetLibSocketAccept() with a small timeout (SysTicksPerSecond() / 10).
Thing is, this means that I'm basically timeslicing between the network and
UI. Thus I have a server that doesn't always respond and a UI that's
unresponsive.
I assume there's a way around this, but no matter how much trawling through
the documentation I can't find anything. So, any help would be much
appreciated.
Problem 2
The second problem is trying to stop and start my server. When I start the
server it connects to the network, then does sets up the socket with open,
bind then listen. This works fine. If I then stop it (basically do
NetLibSocketClose() on the listen socket) and disconnect from the network I
can restart the server and it connects, and does the open/bind/listen with
no problems.
However, if I try to reconnect with the network still open, things don't
work. The open and bind are fine, but when I try to listen I get a 'port in
use' error. Does anybody know what this could be? Am I not closing the
socket properly? Is there something else I have to do?
Thanks in advance for your help,
Cheers
Russell
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/