socket not sending or receiving data

anuradha.k.r_at_sify.com
Date: 02/24/04


Date: 24 Feb 2004 00:45:08 -0800

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



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)