SocketServer - A simple server for messaging between applications and/or computersDownload socketserver version 1 here In developing exhibits, I often have communication needs that extend beyond the capabilities of the programming languages I use. For these situations, I have written a simple server to pass messages back and forth between applications and/or computers. I have also written a number of different clients; some just broadcast messages periodically for testing, some relay messages back and forth with serial ports (or usb-to-serial devices), and some take action on the messages and change their displayed output (like a flash client). Here are some examples of situations in which such a system would be necessary:
The majority of the work I do obviously involves Flash, but I've occasionally needed other programs to talk back and forth, and the simplicity of this server has made these communications easy. The server itself is written in PHP (CLI php, not the Apache plugin that returns website requests). CLI PHP is installed and enabled in the most recent versions of Mac OS 10. It can be quickly and easily installed on most Linux machines; just use a package manager and find CLI PHP. Unfortunately, there is enough variation between PHP on *nix systems and PHP on Windows systems that the server will not currently run on a Windows machine. I have a version of the server that was written specifically for Windows, so at some point in the near future I plan on bringing that code into the application... I'm just not in a big rush because 98% of the time I'm working in 10.5. So here's how the server works:
socketserver.sh takes more parameters than just '-v'... Here is a list of parameters you can pass to the server when starting it up:
All of the above parameters are case-insensitive, especially the ip address, since it should be all numbers and periods. Just for clarification (in case you didn't pick it up yet), this is not the same type of server as something like Apache... those make a connection, take requests, generate a response, broadcast the response to the requesting client, and then break the connection. This server is more for constant communication between multiple clients, since messages go through to everyone that's connected. I guess the easiest way to describe it is through a potential application like an instant messaging system; all clients connected will get all the messages from all the other clients, and can send messages that will go to everyone. Also, since the messages are broadcasted to ALL the connected clients, some sort of protocol should be used for the messages defining who the messages are from (at the very least) and to (useful as well); that way the clients can only take action on stuff that's to them. Important: Avoid setting up a feedback loop; if you take action on a received message that involves sending a new message, make sure that the response won't trigger a new response... for example, Your application: 'if I get a message of "OK" send a message of "OK"' This example would cause your client to repeatedly respond to itself, bringing the server to a grinding halt. This example would work if the recommendation to use a 'to' and 'from' is implemented: Your application: 'if a message is not addressed from me and says "OK" send a message of "OK" to everybody from me' Here's the download link one more time... I created a socket server inI created a socket server in java and use flash as my clients. The problem I ran into was that my clients that used Macs weren't able to connect to my java socket server. Any ideas? By Chad (not verified) at Mon, 2009-01-19 22:25 | reply
This is a great script. IThis is a great script. I wanted to keep track of what my users were doing in real time inside my PHP based site and this saved me from having to write my own simple message server. Now I can log in from anywhere using telnet/putty and get a list of user actions in real time. By Steven Martin (not verified) at Fri, 2009-01-09 09:04 | reply
This looks like a brilliantThis looks like a brilliant means of getting around some of the nasties associated with some inter application communication, thanks! However, when I run the socketserver.sh on OSX 10.5.4, I'm getting the following error : ... Notice: Undefined offset: 19 in /Users/yournamehere/Downloads/socketserverv1/socketserver.sh on line 307 Notice: Undefined offset: 0 in /Users/yournamehere/Downloads/socketserverv1/socketserver.sh on line 358 ... Notice: Undefined offset: 19 in /Users/yournamehere/Downloads/socketserverv1/socketserver.sh on line 358 This seems to have something to do with the client array but I can't tell what, exactly. Any idea what might be happening? By captain of the sea (not verified) at Sun, 2008-09-07 02:27 | reply
|
neat thanks!
neat thanks!