Code Comments
Programming Forum and web based access to our favorite programming groups.Hello together,
I just tryed to make a simple Socket-Connection with a client and a server
which are connected with each other over localhost.
the server:
#!/usr/bin/perl
use IO::Socket;
use strict;
my $server_port = 3434;
my $server;
my $client;
my $in_line;
$server = IO::Socket::INET-> new ( LocalPort => $server_port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => SOMAXCONN )
or die "unable to start server ! $@\n";
while ( $client = $server->accept () )
{
$in_line = <CLIENT>;
print "$in_line \n";
}
close ( $server );
__END_
and the client:
#!/usr/bin/perl
use IO::Socket;
use strict;
my $remote_host = "localhost";
my $remote_port = 3434;
my $socket;
my $data = "test";
$socket = IO::Socket::INET->new ( PeerAddr => $remote_host,
PeerPort => $remote_port,
Proto => "tcp",
Type => SOCK_STREAM )
or die "unable to establishe a connection !\n";
$socket-> send ( $data , $flags ) or die "could not send!\n";
close ( $socket );
__END_
I expact, that the data-string is send by the client to the server. When it
reaches the server, the server put it out, and keep on listening.
But the server does nothing at all, its numb?!?
What did I omitted? How I get the flags? With fcntl ?
Gruss Christian
Post Follow-up to this messageOkay okay, it shold call:
while ( $client = $server->accept () )
{
print "$client \n";
}
close ( $server );
__END_
And so it works, but not as I need. The output is
IO::Socket::INET=GLOB(0x81848d0)
Gruss Christian
--
Christian Stalp
Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
Obere Zahlbacher Straße 69
55131 Mainz
Tel.: 06131/ 17-6852
E-Mail: stalp@imbei.uni-mainz.de
Internet: www.imbei.de
Post Follow-up to this messageOn Sep 28, Christian Stalp said: >$socket-> send ( $data , $flags ) or die "could not send!\n"; To send data to the socket, just print() to it: print $socket "$data\n"; -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.