socket not sending or receiving data

A

anuradha.k.r

hi,
I 'v e written both the server and client side socket programs in
perl( a very small one).My socket is created and shows that the
connection is established with the client.however I am not able to
receive data in server side.I think the client sends the data
properly.Somehow receive does not happen.
Can someone tell me what could be wrong?
My code is part of the sample programs available for socket prgmng in
the net.
Here is the code for both client.

Client:
# !;/usr/perl -w

#client part

use IO::Socket::INET;
$sock = new IO::Socket::INET(
PeerAddr => '130.10.5.76',
PeerPort => '7070',
Proto => 'tcp'
);
die "could not create client socket: $!\n" unless $sock;

print "$sock Hello there!\n";

#send message

print "enter message to be sent:";

#while($msg = <STDIN>){
$msg = <STDIN>;

chomp $msg;
if($msg ne ''){
print "\nsending message\n";
if($sock->send($msg)){
print "\ndone\n";
print $msg;
}
else{
print "message not sent\n";
}
}
close($sock);

print "socket closed\n";

#########################################

Server:


# !/usr/perl -w
#socket server

use IO::Socket::INET;

#create,bind,listen socket
$sock = new IO::Socket::INET(
Localhost => '130.10.5.38',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could notcreate socket: $!\n" unless $sock;

print "socket created\n";
$new_sock = $sock->accept();


while(defined(<$new_sock>)) {
print $_;
}
print "$new_sock";

$msg = "\nReceiving message\n";
#while(1){

if($new_sock->recv($text,4)){
if($text ne ''){
print "\nMessage received\n";
print $text;
}
else{
print "\nMessage is null\n";
print $text;
}
}
else{
print "\nReceive not success\n";
}
#}

close($sock);
close ($new_sock);
print "server socket closed";

regards & thanx,
AV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top