might also want to turn on buffer flusing: $|=1; # somewhere before the read operation, might want to use select to make sure # you ar working with the correct FH
> -----Original Message----- > From: Mark Goland [mailto:[EMAIL PROTECTED]] > Sent: Sunday, December 29, 2002 10:52 PM > To: Mat Harris > Cc: perl > Subject: Re: two-way socket troubleshooting > > > ok, the problem was with send and read. I think send is used with msg > passing. If you are going to use raw sockets, then use raw > writes and reads. > I tested this on a windows machine, so might have to change a > few things on > *niX. > > Server: > > use Socket; > $SOMAXCONN=2; > > > socket(SERVER, AF_INET, SOCK_STREAM, getprotobyname('tcp')) > || die "cant > creat socket $!"; > setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1) || warn "cant make socket > reusable\n"; > bind(SERVER, sockaddr_in(8850, INADDR_ANY)) || die "cant bind > IP to socket > $!";; > listen(SERVER, SOMAXCONN) || die "cant listen on port $!";; > print "server PID $$ is listening\n"; > > while(){ > > > $REMOT_ADDR=accept(CLIENT, SERVER); > > # after connection > > ($R_port,$R_addr)=sockaddr_in($REMOT_ADDR); > $R_addr=inet_ntoa($R_addr); > print "connection from $R_addr on $R_port\n"; > > > > $Length=sysread(CLIENT, $line, 1024); > chomp($line); > print "client said: $line\n"; > syswrite(CLIENT, "thanks\n"); > close (CLIENT); > undef $Length; > > } > > Client: > > > use strict; > use Socket; > my ($remote, $port, $iaddr, $paddr, $proto, $line, $n); > > $remote = 'localhost'; > $port = 8850; > > > $iaddr = inet_aton($remote) || die "no host: $remote"; > $paddr = sockaddr_in($port, $iaddr); > $proto = getprotobyname('tcp'); > > socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; > > connect(SOCK, $paddr) || die "connect: $!"; > > syswrite(SOCK, "Welcome\n"); > > sysread(SOCK, $line,1024); > print "server: $line\n"; > > close (SOCK) || die "close: $!"; > exit; > > > good luck, > Mark > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]