top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

handling multiple TCP connections in perl

+1 vote
72 views

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 Google+ Share Button LinkedIn Share Button Multiple Social 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 https://metacpan.org/release/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
http://poe.perl.org/ ,
https://metacpan.org/module/AnyEvent ,
https://metacpan.org/release/IO-Async , etc.

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

answer Sep 4, 2013 by Naveena Garg

Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...