A Processing socketserver client

Download socketserver Processing client example here

For those of you that are into Processing, here's a socketserver client that draws blue lines on an orange background, a la etch-a-sketch... I really haven't spent as much time as I'd like playing with Processing; it creates java applets, which means that what is created will run on just about any platform out there. My place of business is constantly wanting content created for a specific machine in a specific OS, so most work gets done in Flash, php, or a proprietary language rather than Processing. But I have played with it enough to determine that it is an excellent tool for learning the basics of drawing with code, mainly because it is a community-driven opensource project so anyone can download the IDE and start programming right away. There are several nice examples packaged within the installer, and the structure is pretty consistent with other programming languages that I've encountered. It's also got an excellent reference library; that makes a world of difference when trying to learn a new language. If you are a visual kind of person, haven't done much programming, I highly recommend downloading it and messing around with copies of the example programs. Oh, did I mention that the download is free?

Anyhow, this client demonstrates how to read in messages from a running instance of socketserver. I didn't put a lot of commands in; here's a list:

  • P : pen down (movement will make a line)
  • p : pen up (movement will not draw a line)
  • C : clear the drawing area
  • x,y : move the pen to x,y (x and y should be whole numbers)

Not really much to do here, but not much to go wrong, either. Start up an instance of socketserver with a client (either start it with the -c parameter or open a telnet connection). Then open socketserverClient.pde with Processing. Run the program, switch back to your socketserver client, and type "100,100" (no quotes). You should have a blue diagonal line going from 0,0 (default pen position) to the 100,100 that you just specified.

A few times when I launched the program it threw a bunch of errors at me related to the network connection; since it was working for me 90% of the time, I'm posting this as is, but I plan on actually reading the errors at some point and looking for ways to handle them. If you get them, try stopping and restarting the program. If you keep getting them, leave me a comment below with what version of processing and what operating system you are using and I'll see if I can duplicate the problem.

If someone wanted to practice or learn coding starting with this program as a foundation, I can think of a whole lot of places where more could be added. What about changing the color of the background or the pen stroke? Or drawing on an arc? There's also a problem with the protocol; it assumes that all messages are for it. There's no check to ensure that the message is for this program. Maybe it needs a protocol so it will play nice with other clients. Something like "etch:[command]", perhaps?

I always need to test interactive multimedia prior to client demos and installations. Let's just say that this is an interactive piece because the x and y values could come from any input source we choose to hook it to. Instead of manually typing in sequences of numbers, I'll usually test by creating a php script (another socketserver client) that generates random or incrementing numbers that match the client's protocol, run that script, and walk away for a while. After running it for a while, I can see if it's still responsive and behaving the way I'd intended it to. This program could really use a client like that, because you could define a shape of some kind as a series of x and y values with "p" and "P" mixed in as appropriate. That will probably be the next socketserver client I'll put here, so watch for it.

Here's the sample files one more time...
socketserver Processing client example