|Think about Loose Coupling|
Chat server impossible with Perl?by bronto (Priest)
|on Feb 04, 2005 at 11:33 UTC||Need Help??|
bronto has asked for the
wisdom of the Perl Monks concerning the following question:
Dear brothers and sisters
Building from my few threads experiences so far, I wanted to write some notes and publish them, but I also wanted to move a little forward. I discussed with a friend of mine, that's a Java and J2ME programmer, and he'd like to help me and build a sort of client for J2ME.
Unfortunately (or luckily, as always :-) in J2ME you can't create a server socket, so the principles at the base of my simple chat client of having an application that was both an http server and client couldn't apply. Therefore, we needed a chat server and a protocol; the J2ME chat client could then connect to the chat server and keep the connection open, and all chats would flow in and out from/to that connection.
We designed a small, simple protocol and he created a server using Java. The server does the following:
I was trying to design the same server in Perl, but I am stuck.
I tried to design it using forks, but I encountered a couple of problems:
Then I thought about a full thread approach, but again I hit the limitation that, in my opinion, makes perl threads more similar to a toy than a tool: the impossibility to share objects, especially if they are of the filehandle kin... This makes impossible to have an hash of (ID => SOCKET) shared between the thread that manages the incoming connections and another thread that manages the delivering of user messages, that should run in parallel with it.
My reserve of fantasy, logic and imagination is over for this week. Does anyone of you have a better idea and can try to help me?
Thanks in advance
In theory, there is no difference between theory and practice. In practice, there is.