Click here to Skip to main content
15,074,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have had this problem with threads.
i want to send a tcp packet with threads and i also want to select the amount of threads to do that and when ever a thread sends a packet i want it to tell me that.

i send the packet with simply with:
PERL
$socket->send($data);


so just that in threads, maybe i need to define something that will send it

What I have tried:

this is something i found on some website that cinda works:

PERL
use threads;

use Threads::shared;

sub start_thread {
        my @args = @_;
        $socket->send($data);
}

my $thr = threads->create('start_thread', 'argument');

$thr->join();

$thr->detach();



or something like that. but that dose not tell me and it dont contiue for ever
Posted
Comments
Sergey Alexandrovich Kryukov 28-May-16 21:20pm
   
I know very little about Perl, but all implementations of socket interface are very similar. It's a good idea to dedicate separate threads for all communications. In you use TCP, you need at least two additional threads on the server side (which you didn't even mention, by some reason): to listen to new connection and to perform network read/write itself. On client side, it can be one thread. It is usually a bad idea to introduce variable number of threads. You can have to many, for example, TCP channels, much greater number than the number of CPU cores; it would only slow down your communications...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900