473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Client server program

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.
Feb 14 '08 #1
2 3780
KevinADC
4,059 Expert 2GB
this is all the help I am willing to give you:

http://perldoc.perl.org/perlipc.html
Feb 14 '08 #2
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:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict; 
  3. use Socket; 
  4.  
  5. # use port 5700 as default 
  6. my $port = shift || 5700; 
  7. my $proto = getprotobyname('tcp'); 
  8.  
  9.  # create a socket, make it reusable 
  10.  socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; 
  11.  setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!"; 
  12.  
  13.  # grab a port on this machine 
  14.  my $paddr = sockaddr_in($port, INADDR_ANY); 
  15.  
  16. # bind to a port, then listen 
  17. bind(SERVER, $paddr) or die "bind: $!"; 
  18. listen(SERVER, SOMAXCONN) or die "listen: $!"; 
  19. print "SERVER started on port $port "; 
  20.  
  21. # accepting a connection 
  22. my $client_addr; 
  23. while ($client_addr = accept(CLIENT, SERVER)) 
  24. # find out who connected 
  25. my ($client_port, $client_ip) = sockaddr_in($client_addr); 
  26. my $client_ipnum = inet_ntoa($client_ip); 
  27. my $client_host = gethostbyaddr($client_ip, AF_INET); 
  28.  # print who has connected 
  29.  print " \n got a connection from: $client_host","[$client_ipnum] \n "; 
  30.  # send them a message, close connection 
  31. print CLIENT " \n Smile from the server \n"; 
  32. close CLIENT; 

Client:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict; 
  4. use Socket; 
  5.  
  6. # initialize host and port 
  7. my $host = shift || 'localhost'; 
  8. my $port = shift || 5700; 
  9.  
  10. my $proto = getprotobyname('tcp'); 
  11.  
  12. # get the port address 
  13. my $iaddr = inet_aton($host); 
  14. my $paddr = sockaddr_in($port, $iaddr); 
  15.  # create the socket, connect to the port 
  16.  socket(SOCKET, PF_INET, SOCK_STREAM, $proto) 
  17. a. or die "socket: $!"; 
  18. connect(SOCKET, $paddr) or die "connect: $!"; 
  19.  
  20. my $line; 
  21. while ($line = <SOCKET> ) 
  22. print $line; 
  23.  
  24. close SOCKET or die "close: $!";
Jun 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
15
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...
4
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....
3
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...
2
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:";...
4
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...
4
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...
0
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...
2
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...
2
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.