-
chat avec socket
Bonjour à tous,
j'essaie de créer une sorte de chat entre 2 pc utilisant un socket. Pour la connexion le premier qui lance le programme est l'hote , le 2e le client. Cependant mon test au début pour savoir qui est l'hote ou le client ne semble pas fonctionner .... Et même si j'essaie de forcer un à être hote et l'autre client ça ne fonctionne pas non plus... Qqn aurait il une idée du problème ?
Voici mon début de code :
#!/usr/bin/perl -w
#use strict;
use IO::Socket;
#private
my ($host, $port, $kidpid, $skt, $line);
# get host address and port from the command line.
die "usage: $0 host port" unless (@ARGV == 2);
($host, $port) = @ARGV;
print "Welcom to the Chat Client, connex process\n";
$skt = IO::Socket::INET->new("$host:$port");
#if the other is waiting for us, we connect to him
#otherwise we wait him
if ($skt) {
print "we are the client";
print STDERR "[Connected to $host:$port]\n";
}
#We are the "server"
else {
print "We are the server";
$s = IO::Socket::INET->new(LocalAddr => 'localhost',
LocalPort => 50007,
Listen => 1,
Reuse => 1);
$skt = $s->accept();
print STDERR "[Connected to $host:$port]\n";
}