#!/usr/bin/perl -w #tcpserver.pl use strict; use Data::Dumper; use IO::Socket::INET; # flush after every write $| = 1; my (@arr,@art,%hsh,$cin,$tims,$status,$data,%vrf,$x,$start); my ($socket,$client_socket,@client_reply,@client_verify,$client_reply); my @hash=({port=>'',tim=>''}); my ($peer_address,$peer_port); my $times_connect=0; # creating object interface of IO::Socket::INET modules which internally does # socket creation, binding and listening at the specified port address. $socket = new IO::Socket::INET ( #LocalHost => '127.0.0.1', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1 ) or die "ERROR in Socket Creation : $!\n"; my $timeData = scalar(localtime); print $timeData."\n"; print "SERVER Waiting for client connection on port 5000"; my $times_connected=0; $start=1; while(1) { # waiting for new client connection. $client_socket = $socket->accept(); # get the host and port number of newly connected client. $peer_address = $client_socket->peerhost(); $peer_port = $client_socket->peerport(); push @arr,$peer_port; $hsh{$peer_port}=1; if($start eq 1) # The very first client. { $status=1; # get your own MD5 } if($start >1) { $status=$client_reply; #It has to write its own this time. } print "\nAccepted New Client Connection[$start] From : $peer_address, $peer_port\n at".scalar(localtime); # write operation on the newly accepted client. print $client_socket "$status\n"; $data = <$client_socket>; chomp($data); print "Received from Client :",$data; push @client_reply,$data; $client_reply.="$data {}"; print "\n\n LIST->$client_reply"; $start++; } $socket->close();