Search This Blog

Saturday, June 6, 2015

Socket Configuration With The Client System ..

********************************************

06-June-2015


Requirements beore going to this article:
i)Basic idea of socket and its use
ii)Usage of Perl modules

********************************************

Generally Socket configuration consists of..

Creating Socket
Bind it to port
Client Connection Establishment

##Related  library is Socket INET (i.e. Socket::INET)

Below is the skeleton code..

where XXX needs values with repect to local configuration.


socket = new IO::Socket::INET (
LocalHost => 'XXX',
LocalPort => 'XXXX',
Proto => 'tcp',
Listen => 5, #5 for tcp, varies based on configuration
Reuse => 1
) or die "error in creation of scket: $!  ”;


## repeat a infinite loop till the connection is success full something like 

while(1)
{

$client_soc = $socket->accept();

#to fetch host
$peer_address = $client_sock->peerhost();
#to fetch port num
$peer_port = $client_sock->peerport();

#this is end of the connection

$data = “data 4m Server”;
print $client_sock “$data\n”;

$data = <$client_socket>;

print “ $data is received from clinet s\n”;
}
#finally end of the connection by 
$socket->close();

TCP Socketing

Generally socket operation contains..