develooper Front page | perl.beginners | Postings from February 2002

Re: sockets help??

Thread Previous
From:
walter valenti
Date:
February 6, 2002 03:24
Subject:
Re: sockets help??
Message ID:
3C6112CA.9010900@yahoo.it
>
>
>I am trying to write winsock software to have one client connect to three different server computers (not simultaneously) by simple sock stream.  I tried to create one socket and connect to each computer.  Once the previous connection is completed with one of the computers, I would change the last part of the IP to connect to another computer, but with the same socket.  I used the same port for all connections.  It did not work.  Any suggestions?
>

I don't know the winsock implemantation...but:

When you close the socket, you destroy the socket descriptor => you must 
create a new socket descriptor, for examle:

sub net{
    socket(SO,PF_INET,SOCK_STREAM,getprotobyname('tcp')) || die"$!\n";
    my $ip=$_[0];
    my $port=$_[1];
    my $dest=sockaddr_in($port,inet_aton($ip));
    if(connect(SO,$dest)){
    ###your client code ###
    close(SO);
    return 1;
    }
    else{
    close(SO);
    return 0;
    }
}

    Walter

>
>
>When I use closesocket() function, does that make that socket unusable?
>After you connect to a server computer, then leave continue doing something else, is the connection still live?
>
>Thanx!
>
>Raymond
>




Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About