473,378 Members | 1,470 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,378 software developers and data experts.

Client/Server Password question

Hi everyone,

I've recently started experimenting with PERL in the area of sockets and networks.

I've gotten the two programs listed below working on my own machine (through localhost).

However, I want to prompt the server to ask the client for a password, printing a message if the correct password is entered or not.

The problem I'm having is how do I send the values I read in in the client program to the server program?
I know how to check for these values but I'm stumped as to how to send the string that's entered client-side to the server-side. Or am I completely on the wrong track?


Server Program

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. # server2way.pl - a server that reads from
  3. # and writes to a client
  4. use strict;
  5. use IO::Socket;
  6. use Sys::Hostname;
  7. my $sock = new IO::Socket::INET(
  8.                    LocalHost => 'localhost',
  9.                    LocalPort => 7890,
  10.                    Proto     => 'tcp',
  11.                    Listen    => SOMAXCONN,
  12.                    Reuse     => 1);
  13. $sock or die "no socket :$!";
  14. STDOUT->autoflush(1);
  15. my($new_sock, $buf);
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. while ($new_sock = $sock->accept()) 
  23.  
  24. {
  25.  
  26.  
  27.  
  28.         while (defined($buf = <$new_sock>)) 
  29.  
  30.         {
  31.  
  32.            foreach ($buf) 
  33.  
  34.            {
  35.                     /^HELLO$/ and print($new_sock "Enter Name: \n"), last;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.                      /^NAME$/  and print($new_sock "Enter Password: \n"), last;
  44.  
  45.  
  46.                    /^DATE$/  and print($new_sock scalar(localtime), "\n"),last;
  47.  
  48.                    print $new_sock "DEFAULT\n";
  49.            }
  50.  
  51.         }
  52.  
  53.  
  54.        close $new_sock;
  55. }
  56.  
  57.  
  58.  


Client Program

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #!/usr/bin/perl -w
  4. # client2way.pl - a client that writes to
  5. # and reads from a server
  6. use strict;
  7. use IO::Socket;
  8. my $host = shift || 'localhost';
  9. my $port = shift || 7890;
  10. my $sock = new IO::Socket::INET(
  11.                   PeerAddr => $host,
  12.                   PeerPort => $port,
  13.                   Proto    => 'tcp');
  14. $sock or die "no socket :$!";
  15. # send message to server
  16.  
  17.  
  18. print $sock "HELLO\n";
  19. print scalar <$sock>;
  20. my $name =<STDIN>;
  21.  
  22.  
  23.  
  24. print $sock "NAME\n";
  25. print scalar <$sock>;
  26. my $guess=<STDIN>;
  27.  
  28.  
  29. print $sock "DATE\n";
  30. print scalar <$sock>;
  31.  
  32.  
  33. print $sock "NONE\n";
  34. print scalar <$sock>;
  35.  
  36.  
  37.  
  38.  
  39. close $sock;
  40.  
  41.  
  42.  
Mar 6 '10 #1
0 1297

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

Similar topics

5
by: Bas Bloemsaat | last post by:
Hi, This maybe more of a Javascript question than PHP, but as it requires some understanding about what is sent over the line and what not, I assume this is the better forum to ask. I'm...
4
by: Frodo | last post by:
I have a problem establishing a link between Visual Studio.NET 2003 and SQL Server 2000. Both are installed on a Windows Server 2003, standard version. Visual Studio.NET Issues...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
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...
0
by: Joey Edelstein | last post by:
Hi, We are trying to add a Client Certificate support for our web app that emulates a hardware device web app. The hardware uses a 2 factors authentication, which requires a Web Service client...
0
by: gg | last post by:
I'm currently trying to strengthen up the security on a large ASP.NET application (a web content management system). The primary objective is to prevent people from evesdropping for passwords and...
4
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For...
5
by: Nate | last post by:
We are attempting to make a request to a web service (we will refer to it as XXXServices) hosted on a Web Logic server from a C# SOAP client. The server responds with a 401 Unauthorized error...
2
by: Frank Swarbrick | last post by:
I am trying to understand "client authentication" works. My environment is DB2/UDB LUW 8.2 on zSeries SLES9 as the database server and DB2 for VSE 7.4 as the client. We currently have DB2/LUW set...
3
by: dynamo08 | last post by:
Hi, I am new to socket programming, I wrote an ftpclient which connects to an ftp server and downloads a file to the client computer. Now in one client connection I want to download multiple files...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.