about socket program

about socket program

Post by Jun » Thu, 03 Apr 2003 19:46:09



I want to write server program accepts a query from a client program asking
about the number of users logged in ot it, and replies to the client with
the information. How can I do?
 
 
 

about socket program

Post by Barry Margoli » Fri, 04 Apr 2003 01:10:41




>I want to write server program accepts a query from a client program asking
>about the number of users logged in ot it, and replies to the client with
>the information. How can I do?

The server should keep a global counter of the number of clients it has.
Whenever a client connects, it increments it; when a client disconnects, it
decrements it.  And when a client sends a query for the number of users
logged in, it sends back the current value.

If that's not the kind of answer you were looking for, you're going to have
to be more specific about the problem you're having.

--

Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

about socket program

Post by Absolute Newb » Fri, 04 Apr 2003 01:53:10



> I want to write server program accepts a query from a client program asking
> about the number of users logged in ot it, and replies to the client with
> the information. How can I do?

Well, a "very" simple way to do this is by using NetCat. Here is how I
do it:

[1] Write the following small script:

    #!/bin/sh
    echo There are `who | wc -l` users on the system.

Name it whatever you like (for instance, "myscript"), and chmod it to
have execute permissions.

[2] Launch NetCat in an "endless" loop:

    $ while true; do nc -l -p 65432 -e myscript; done &

Note: you must compile NetCat with GAPING_SECURITY_HOLE defined in
order to be able to use the -e option. There is a way around this if
you use named pipes, but it is a bit more complicated then just typing
-DGAPING_SECURITY_HOLE when compiling NetCat.

[3] Telnet to this machine to port 65432 and you'll get your response
immediately.

This might not be exactly what you meant, because there is no client
request, but it is quite simple and does fulfill your requirements.

Best regards,

AbsNewbie

 
 
 

about socket program

Post by Jun » Fri, 04 Apr 2003 07:32:16


I have a file name hostaddress.txt
which is containing a list of host addresses.
www.yahoo.ca
www.cbc.ca
www.sasktel.com
www.shaw.ca
www.google.ca
www.hotmail.com
www.daum.net
www.futureshop.ca
ca.msn.com
www.ebay.ca
www.expedia.ca

the server program accepts a query from a client program asking
about the number of users logged in on hostaddress.txt's each list.,
and repies to the client with the information.

 
 
 

about socket program

Post by William Par » Fri, 04 Apr 2003 08:13:06



> I have a file name hostaddress.txt
> which is containing a list of host addresses.
> www.yahoo.ca
> www.cbc.ca
> www.sasktel.com
> www.shaw.ca
> www.google.ca
> www.hotmail.com
> www.daum.net
> www.futureshop.ca
> ca.msn.com
> www.ebay.ca
> www.expedia.ca

> the server program accepts a query from a client program asking
> about the number of users logged in on hostaddress.txt's each list.,
> and repies to the client with the information.

man who
man faucet
man nc (or netcat)

--

Linux solution for data management and processing.

 
 
 

about socket program

Post by Jun » Fri, 04 Apr 2003 09:13:48


the client program receives as a
parameter the hostaddress.txt.
client queries each of hosts in the list contained
in hostaddress.txt for the number of users logged in on
each. after it has received results from the host, it
prints out the address for the machine with the
smallest number of users logged in.
 
 
 

about socket program

Post by Barry Margoli » Fri, 04 Apr 2003 10:13:18




>I have a file name hostaddress.txt
>which is containing a list of host addresses.
>www.yahoo.ca
>www.cbc.ca
>www.sasktel.com
>www.shaw.ca
>www.google.ca
>www.hotmail.com
>www.daum.net
>www.futureshop.ca
>ca.msn.com
>www.ebay.ca
>www.expedia.ca

>the server program accepts a query from a client program asking
>about the number of users logged in on hostaddress.txt's each list.,
>and repies to the client with the information.

AFAIK, there's no standard protocol to ask a web server how many users are
logged into it.  So unless you have some connection to all those web
hosting services and can get them to implement a protocol for you, you're
SOL.

--

Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

about socket program

Post by Jun » Sat, 05 Apr 2003 18:47:56


the client program receives as a
parameter the hostaddress.txt.
client queries each of hosts in the list contained
in hostaddress.txt for the number of users logged in on
each. after it has received results from the host, it
prints out the address for the machine with the
smallest number of users logged in.

hostaddress.txt
www.yahoo.ca
www.cbc.ca
www.shaw.ca
www.google.ca
www.hotmail.com
www.futureshop.ca
ca.msn.com
www.ebay.ca
www.expedia.ca

 
 
 

about socket program

Post by Jun » Wed, 09 Apr 2003 08:15:40


thanks for your help.
But bourne shell which I am using doesn't have
nc (netcat) command.
 
 
 

about socket program

Post by Michael Acost » Wed, 09 Apr 2003 11:15:45



> thanks for your help.
> But bourne shell which I am using doesn't have
> nc (netcat) command.

nc is not a shell command - it's a seperate binary. Download, compile,
and install netcat.

To save you a google, here it is:
http://www.atstake.com/research/tools/network_utilities/

 
 
 

about socket program

Post by Jun » Wed, 09 Apr 2003 13:14:24


thanks.
I am installing now.
actually, I have one more question.

 wrote server and client program like these:

#!/bin/sh

echo "There are `who | wc -l` users on this system."

client program:
    #!bin/sh

if [ $# = 1 ]
then
    echo "You need one argument : file "
    exit 1
fi

cmd=$0
filename=$1

while read -r address
do
   array[0]=$address
   telnet $address 80 | myserver
done < $1

also, the hostaddress.txt is
www.yahoo.ca
www.cbc.ca
www.sasktel.com
www.shaw.ca
www.google.ca
www.hotmail.com
www.futureshop.ca
ca.msn.com
www.ebay.ca
www.expedia.ca
www.zdnet.com
www.cnn.com

after I executed the client program,
I got this result each hostaddress.

array[0]=www.yahoo.ca
"There are 2 users on this system

what was wrong?

 
 
 

about socket program

Post by Chris F.A. Johnso » Wed, 09 Apr 2003 14:10:41



> thanks.
> I am installing now.
> actually, I have one more question.

>  wrote server and client program like these:

    What server program?

Quote:> #!/bin/sh

> echo "There are `who | wc -l` users on this system."

    This just tells you how many people are on the machine that's
    running the script, not a remote computer.

Quote:> client program:
>     #!bin/sh

> if [ $# = 1 ]
> then
>     echo "You need one argument : file "
>     exit 1
> fi

> cmd=$0
> filename=$1

> while read -r address
> do
>    array[0]=$address

   What's the array for? You don't use it.

Quote:>    telnet $address 80 | myserver

   What is this supposed to do?

Quote:> done < $1

> also, the hostaddress.txt is
> www.yahoo.ca
> www.cbc.ca
> www.sasktel.com
> www.shaw.ca
> www.google.ca
> www.hotmail.com
> www.futureshop.ca
> ca.msn.com
> www.ebay.ca
> www.expedia.ca
> www.zdnet.com
> www.cnn.com

> after I executed the client program,
> I got this result each hostaddress.

> array[0]=www.yahoo.ca
> "There are 2 users on this system

    Because you are not running the "server" on the remote machines;
    you are running it on your local box. You are trying to pipe the
    output of the telnet command into th estdin of your script ON YOUR
    LOCAL COMPUTER, and the script doesn't read stdin.

    Even if it did, telnet command is not going to produce anything;
    how are you giving it a login name? How are you giving it a
    password?

    What makes you think you can get a telnet connection to a web
    server?

Quote:> what was wrong?

    It would be quicker to ask what is right.

    Did you read any of the earlier replies to your posts?

    What part of Barry's reply did you not understand?

    To refresh your memory, here is an abbreviated version of what he
    told you:

Quote:> You can't find out how many users are logged into a web site.
> You can't find out how many users are logged into a web site.

    Get it?

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

about socket program

Post by William Par » Wed, 09 Apr 2003 15:31:37



> www.yahoo.ca
> www.cbc.ca
> www.sasktel.com
> www.shaw.ca
> www.google.ca
> www.hotmail.com
> www.futureshop.ca
> ca.msn.com
> www.ebay.ca
> www.expedia.ca
> www.zdnet.com
> www.cnn.com

> after I executed the client program,
> I got this result each hostaddress.

> array[0]=www.yahoo.ca
> "There are 2 users on this system

> what was wrong?

There is nothing wrong.  You got the right answer.  If you were
expecting different answer, post what you typed and what you got for
<www.yahoo.ca>.

--

Linux solution for data management and processing.

 
 
 

1. socket timeout? (socket programming question)

I have a process that opens a TCP server socket via socket/bind/listen.
Sometimes the process dies unexpectedly. When I try to start another
process to bind to the same port, I get EADDRINUSE returned from bind;
the socket is already in use, even though the other process that had
it open is dead. After about 30 seconds, though, I can bind to that
port again.

I know almost all Unix kernels do this, but why? Is there some sort of
garbage collection process in the kernel that occasionally checks all
sockets that are marked in use to check that they really are?

What should I be doing in my own server process to ensure that it
closes the socket properly so Linux doesn't think the socket is in use?

Thanks
  Nelson

2. Dial in

3. Anyone do and socket programming and modem programming on AIX?

4. native threads in linux???

5. socket programming question.

6. Time Zone setting

7. Socket programming: difference between Unix and Windows

8. REQ: Prob w/ RH5.2 and Adaptec 2940 install

9. socket programming miracles

10. NEW EMAIL LIST: IPC/Middleware/Socket Programming

11. Raw Socket Programming

12. Where to find docs of Network/Socket Programming API of Linux Kernel 2.4.7?

13. Socket programming