Non blocking sockets in Perl
How to make such a socket?:)
I understood that there are 2 ways: using IO::Socket using Fcntl ? I'm sort of familiar with IO::Socket, and I write simple IRC bots/servers. I thought that $sock->autoflush(1); $| = 1; makes the socket non-blocking, but a friend of mine just laughed and said that I'm wrong :) He said that I better use Fcntl, but it still could be done with IO::Socket... I'm confused. Let's say according to me, a non-blocking socket allows other parts of the code to be executed in the same time where the socket is being read or wrote. This is how I do with IO::Socket: Code:
IO::Socket -> create the socket I want to make simple application: a timer bot. Let's say at every 30 seconds, it writes a line to the socked, and uses time() function. I don't know even where from to start. Somebody give me a direction please? |
Anyone help?
At least show me a perl forum where I could ask :) |
You can use the four argument form of select() to check whether a handle (like a socket) has input waiting. However, IO::Handles (which include IO::Sockets) have the blocking function (for example, $sock->blocking(0)) to turn blocking on and off.
|
Here's an example:
Code:
print "create_listening_socket()\n"; get stuck waiting. You may or may not want this. See Perl Cookbook chap 17 |
All times are GMT -5. The time now is 09:56 PM. |