top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

handling multiple TCP connections in perl

+1 vote

I'm looking for some good documentation on how to handle multiple TCP connections at the same time. Already have the book Network Programming with Perl (Lincoln D. Stein)

Having a client / server based script that works with a single stream of network data in a single session e.g. a mail server that spawns a new process for every session, I get how that works.

But when I want to do multiple read/write sessions over different sockets I get totally lost.. Looked into IO::select and stuff but I'm just missing some good simple clean examples.

Example.. Client connects to server.. Server keeps sending messages that are passed to the client. Client connects to 2nd source.. And needs to read/write to both the server and to the 2nd source..

posted Sep 4, 2013 by Anderson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Event frameworks will be useful if you want to handle multiple connections within the same process in a powerful and efficient way.

However, for simplicity, I'd recommend a look at Net::Server , which makes this kind of thing rather simple, and provides multiple "personalities" depending on how you want your daemon to work - forking a new process for each connection, pre-forking so some "worker" processes are always available, multiplexing to handle multiple connections within one process, etc.

It takes away a lot of the hard work for you.

answer Sep 4, 2013 by Ahmed Patel
0 votes

I believe that book is heavily outdated.

Anyway, you should look at an event-driven/asynchronous-IO framework such as , , , etc.

Using one of them will facilitate most of the heavy lifting for you.

answer Sep 4, 2013 by Naveena Garg