I 've to write a client server program for my assignment at college......
The server listens at some port in one machine and the client is running on some other machine......
I 'll 've to execute a command from the client so that the command in executed on the server. Please guide me. A small hint for the start is appreciated.
2 3780
The bellow program has got two parts:
A server and a client
The server send message to the client and the client print that message.
Server: - #!/usr/bin/perl
-
use strict;
-
use Socket;
-
-
# use port 5700 as default
-
my $port = shift || 5700;
-
my $proto = getprotobyname('tcp');
-
-
# create a socket, make it reusable
-
socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
-
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!";
-
-
# grab a port on this machine
-
my $paddr = sockaddr_in($port, INADDR_ANY);
-
-
# bind to a port, then listen
-
bind(SERVER, $paddr) or die "bind: $!";
-
listen(SERVER, SOMAXCONN) or die "listen: $!";
-
print "SERVER started on port $port ";
-
-
# accepting a connection
-
my $client_addr;
-
while ($client_addr = accept(CLIENT, SERVER))
-
{
-
# find out who connected
-
my ($client_port, $client_ip) = sockaddr_in($client_addr);
-
my $client_ipnum = inet_ntoa($client_ip);
-
my $client_host = gethostbyaddr($client_ip, AF_INET);
-
# print who has connected
-
print " \n got a connection from: $client_host","[$client_ipnum] \n ";
-
# send them a message, close connection
-
print CLIENT " \n Smile from the server \n";
-
close CLIENT;
-
}
Client: - #!/usr/bin/perl
-
-
use strict;
-
use Socket;
-
-
# initialize host and port
-
my $host = shift || 'localhost';
-
my $port = shift || 5700;
-
-
my $proto = getprotobyname('tcp');
-
-
# get the port address
-
my $iaddr = inet_aton($host);
-
my $paddr = sockaddr_in($port, $iaddr);
-
# create the socket, connect to the port
-
socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
-
a. or die "socket: $!";
-
connect(SOCKET, $paddr) or die "connect: $!";
-
-
my $line;
-
while ($line = <SOCKET> )
-
{
-
print $line;
-
-
}
-
close SOCKET or die "close: $!";
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Microsoft |
last post by:
I'm about to start converting my application from a old-style monolith exe
(with flat files and limited database support for sharing some of the data)
to a layered .NET SQL server version. I have...
|
by: Michael Rybak |
last post by:
hi, everyone.
I'm writing a 2-players game that should support network mode. I'm now
testing it on 1 PC since I don't have 2. I directly use sockets, and
both client and server do...
|
by: Prince Kumar |
last post by:
I joined a company recently and they have a java program which hangs
(does nothing) after a while. This is no way consistent. It could
succeed quite a few times and can fail a few other times....
|
by: Roy Souther |
last post by:
Trying to get the unixODBC to work connecting to an IBM DB2 UDB V8.1. The
DB2 server is running on Red Hat 8 and is tested and confirmed to be
serving connections to Windows 98 clients using the...
|
by: Matt |
last post by:
I wrote the tcp socket client-server program that the server will
echo the message received from the client.
In client program:
char sendBuf;
while(1)
{
cout << "Enter message:";...
|
by: Goh |
last post by:
Hi,
I would like to know how can we implement a web page that
intelligent enough to unique identify that pc have been visit before without
any cookies and login user require.
I have try...
|
by: rajbala |
last post by:
Hi all,
I am a newbie to JSP. I had a program in client and server by using java.
But i want the same program in JSP. Please help me.
server:
// TCP server which waits...
|
by: ollii |
last post by:
Hello evryboody, i created client and srever program that they can both communicate together by TCP and UDP, but when i want to send message to server from client i get error on the server i get...
|
by: nsaffary |
last post by:
hi
I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
|
by: fredszky |
last post by:
Hello
I am very new to perl, however i managed to make this server/client work with udp, now i would like to do the same thing but with TCP/IP, what must i do?
Server:
#!perl -w
# Server...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |