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
----- Original Message -----
From: "Mat Harris" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 28, 2002 10:27 PM
Subject: two-way socket troubleshooting
i have a client and server which I want to be able to have communicate in
full-duplex. I need the client to send a string to the server, the server to
check it and then return a status code (plus some other stuff).
I have the client and server (see attached .txt files) but when I run them,
attemping to do a read() and send() from both sides, the client hangs.
I have tried adding a sleep() but that has no effect.
please can someone look them over and tell me where I am going wrong.
thanks guys
--
Mat Harris OpenGPG Public Key ID: C37D57D9
[EMAIL PROTECTED] www.genestate.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]