I can search and I've already looked at the wikipedia entry and in some other places, but even though I have some programming experience, I don't really grasp the concept. Can you treat me like a 10 year old and give me a clear explanation on socket communication?
Unix Sockets – Simple Explanation
socketsunix
Related Solutions
The question is whether you'd rather the linking application run on your web server (as a relay server) or the desktop (your app accepts lots of connections). That's a design decision, I think, rather than a programming one.
Somewhere you need an application that will accept large numbers of connections. One per instance of the web app, presumably. A million is fairly straightforward and doesn't have to be done in C (example uses erlang and duplicates the code using C).
How many commands are you looking at, total, and how many instances of the web app (tens? thousands? millions?) If it's millions, it doesn't really matter whether you funnel those down using a relay, you're going to spend a lot of time dealing with replication and multiple instances of your endpoints. A million instances sending one command a minute is 16k commands a second.
I think the identifier question is pretty obvious - use the native identifier that comes with the connection (the socket handle or class reference), then whatever mapping system your language provides to link that to the ID of the web app or command. If you must construct your own ID and don't care about the identity of the command source, just use the IP details directly, otherwise use the user or command ID that you have. It's much easier when debugging to see
user 123456 issued command Fubar(everything) from 192.168.0.255:54012
than have an artificial ID in there (or have to look it up).
I suggest the ID be the source address and port, plus the input port (your IP will be fixed, unless you have multiple IPs in which case store that too). With IPv4 that's 32 bits per IP plus 16 per port, for a maximum of 96. With IPv6 it's 160 bits. Either way, that's not going to be your biggest memory suck. Once you put that into a list of some sort you're going to have a pointer or a native int, which becomes your "real ID". Ideally you'll be able to use a direct link into the network layer in your software for that, to save a layer of indirection.
Best Answer
Let me give you an example: Say you want to communicate/chat with your friend, who lives not at your address. For that to happen, you have to establish a "communication channel". Say, you want to do this communication using telephones. You know that there is a network of telephone lines in the city that is extended to every house.
Now, there is a telephone socket in your house, and one in your friends house. For the communication to take place, you and your friend have to connect to the network by plugging your phone to the socket, at the both end of the communication. Sockets in programming is the same, conceptually, as the telephone sockets.
In programming, you have two processes (running programs) that want to communicate with each other. For that, they have to establish a communication link between themselves. Again, there is a network available, they just need to connect to this network using some sort of sockets. Unix sockets are one such socket that provides this connectivity/pluggability to the network. So, in each of the two programs, you will have some piece of code that does the job of connecting to the network through sockets.
The rest are details.