59
|
1 |
#!/usr/bin/perl -w
|
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
use strict;
|
|
18 |
use IO::Socket qw(:DEFAULT :crlf);
|
|
19 |
|
|
20 |
use constant DEFAULT_ADDR => '192.168.3.100';
|
|
21 |
use constant MY_ECHO_PORT => 5000;
|
|
22 |
my ($byte_out, $byte_in) = (0,0);
|
|
23 |
$/ = "\n";
|
|
24 |
$| = 1;
|
|
25 |
|
|
26 |
print "\nUsage: client.pl tcp|udp [ip] [port]\n\n";
|
|
27 |
|
|
28 |
my $quit = 0;
|
|
29 |
$SIG{INT} = sub { $quit++ };
|
|
30 |
|
|
31 |
my $tcp = shift;
|
|
32 |
my $address = shift || DEFAULT_ADDR;
|
|
33 |
my $port = shift || MY_ECHO_PORT;
|
|
34 |
|
|
35 |
print "\nTry to connect to a $tcp server of $address:$port...\n";
|
|
36 |
|
|
37 |
my $sock = IO::Socket::INET->new(PeerAddr => $address,
|
|
38 |
PeerPort => $port,
|
|
39 |
Proto => $tcp)
|
|
40 |
or die "Can't connect: $!\n";
|
|
41 |
|
|
42 |
while (my $msg_out = <>)
|
|
43 |
{
|
|
44 |
last if $msg_out =~ /^\.$/;
|
|
45 |
print "out: $msg_out\n";
|
|
46 |
$sock->send($msg_out);
|
|
47 |
|
|
48 |
my $msg_in;
|
|
49 |
$sock->recv($msg_in, 10000);
|
|
50 |
print "in: $msg_in\n";
|
|
51 |
}
|
|
52 |
|
|
53 |
close $sock;
|
|
54 |
|
|
55 |
|
|
56 |
|