NetSocket - Helpful or harmful?

So I’ve started working on network applications, and that means using NetLib. Unforunately, I have a decision I keep flip-flopping on, and thus not really getting anywhere with my code: namely, whether or not to use Palm’s NetSocket library.

Advantages of NetSocket:

  • For a lot of things, it provides higher level interfaces to functions.
  • It’s written by PalmSource, and is less code for me to maintain.

Disadvantages:

  • Some of the most interesting code in NetSocket is labelled as “debug use only.”
  • NetSocket.c uses global variables as if they were going out of style.
  • Using NetSocket requires some of the “Unix headers.”

Global variables are bad because it means if your code relies on them it will not work in notifications. The Unix headers are bad because they’re undocumented, incomplete and in some cases inaccurate.

So, those of you who develop network applications — what do you do?

Update: Jon Hays of Hazelware (highly recommended reading for Palm programmers) brought up a couple other points in email and in a comment:

The NetSocket stuff is ok, but there are two main problems with it. First, is the globals. Normally that’s not an issue but if you ever want to do things outside of the normal launch code, you’re out of luck. That in itself isn’t so bad because you can always refactor it yourself to get rid of those nasty things. However, the primary reason that I don’t use it is because of the lack of threads on the PalmOS. What I mean is that to not lock up the UI during lengthy operations, I have to alter my event loop to process socket data as an entirely separate operation. If I used the NetSocket junk, I would be subject to yet another layer of rules and abstraction. A good example of that is NetUTCPOpen. If I called NetUTCPOpen to connect to a remote server, my whole application would lock up during that one function call. The better way to do it is to set the socket into non-blocking mode myself and check its status during my event loop. As I write this, I realize that probably sounds uglier than it is, but really it’s just one extra function in my event loop.

4 Responses to “NetSocket - Helpful or harmful?”

  1. Allen Pike Says:

    NetSocket.c uses global variables as if they were going out of style.

    But global variables are going out of style! Ha ha. Sorry, couldn’t resist.

  2. Steven Fisher Says:

    You know, I was thinking of putting a smartass comment about that in my post. “Global variables are going out of style. But that’s no reason to USE them.” But I forgot to add it. So I’m glad you to got it. :)

  3. Jonathan Hays Says:

    Hi Steven,
    Thought it would be nice to stick my email message to you here for posterity. :-)

    The NetSocket stuff is ok, but there are two main problems with it. First, is the globals. Normally that’s not an issue but if you ever want to do things outside of the normal launch code, you’re out of luck. That in itself isn’t so bad because you can always refactor it yourself to get rid of those nasty things. However, the primary reason that I don’t use it is because of the lack of threads on the PalmOS. What I mean is that to not lock up the UI during lengthy operations, I have to alter my event loop to process socket data as an entirely separate operation. If I used the NetSocket junk, I would be subject to yet another layer of rules and abstraction. A good example of that is NetUTCPOpen. If I called NetUTCPOpen to connect to a remote server, my whole application would lock up during that one function call. The better way to do it is to set the socket into non-blocking mode myself and check its status during my event loop. As I write this, I realize that probably sounds uglier than it is, but really it’s just one extra function in my event loop.

  4. Steven Fisher Says:

    Thanks Jonathan. I updated the text to include your comments… something I wanted to do as soon as I got that wonderful email, but I was reluctant to do so without permission. :)

Leave a Reply