perl chat server

Discussion in 'Perl Misc' started by Majid Dehghan, Nov 30, 2012.

  1. hey everyone,
    i'm new to Perl,i'm curios to know how to send a message to a specific user, EX:from user A to user B,not to everyone,
    thanks in advance.
     
    Majid Dehghan, Nov 30, 2012
    #1
    1. Advertising

  2. Majid Dehghan <> wrote:
    >i'm new to Perl,i'm curios to know how to send a message to a specific user, EX:from user A to user B,not to everyone,


    Usually you use email. On CPAN (cpan.org) you will find numerous modules
    that help dealing with any aspect related to email.

    jue
     
    Jürgen Exner, Nov 30, 2012
    #2
    1. Advertising

  3. thanks for the reply,
    but this is a simple chat server,i mentioned it in subject,
    after accepting clients,i want to be able to send a message from one user to another one,just the two of them (something like private message)
    like keeping all the connected socket in an array,but i just don't know how to!
    thanks
     
    Majid Dehghan, Nov 30, 2012
    #3
  4. Majid Dehghan

    Jim Gibson Guest

    In article <>,
    Majid Dehghan <> wrote:

    > hey everyone,
    > i'm new to Perl,i'm curios to know how to send a message to a specific user,
    > EX:from user A to user B,not to everyone,
    > thanks in advance.


    I googled for 'perl chat server' and came up with several
    interesting-looking links, including this one:

    <http://poe.perl.org/?POE_Cookbook/Chat_Server>

    --
    Jim Gibson
     
    Jim Gibson, Nov 30, 2012
    #4
  5. much appreciated Jim Gibson,
    but you see ("# Handle a connection. Register the new user, and broadcast a message # to whoever is already connected.")
    i don't want that,i just want to send a message from one user to only another one,not all connected client.
    i googled it too,but i need someone to guide me

    thanks
     
    Majid Dehghan, Nov 30, 2012
    #5
  6. Majid Dehghan <> wrote:
    >thanks for the reply,
    >but this is a simple chat server,i mentioned it in subject,
    >after accepting clients,i want to be able to send a message from one user to another one,just the two of them (something like private message)
    >like keeping all the connected socket in an array,but i just don't know how to!
    >thanks


    Honestly, what on earth are you talking about? Do you want to write an
    Instant Messaging System (IM) from scratch? Do you want to connect to an
    existing IM server using a Perl client? Do you have a multi-user chat
    system up and running (WHICH ONE?) and want to enhance its
    functionality? What do you want?

    Sockets and arrays are implementation details which are waaaaaaaay to
    detailed at this time.

    jue
     
    Jürgen Exner, Nov 30, 2012
    #6
  7. Consider a chat server,clients connect to this server and chat to each other,this is my code so far:
    use strict;
    use IO::Socket;
    use IO::Select;
    my $srv=IO::Socket::INET->new(LocalPort=>'5000',Proto=>'tcp',Reuse=>1,Listen=>5) or die 'SOCKET';
    print "SEVER READY\nWaiting For Connection\n";
    my $sel=IO::Select->new;
    $sel->add($srv);

    while(my @inp=$sel->can_read()) {
    foreach my $c (@inp) {

    if($c eq $srv) {
    my $clnt=$srv->accept();
    my $host=$clnt->peerhost();
    my $port=$clnt->peerport();
    my $c=$sel->count;
    print $clnt "--- $c users(s) online ---\nPress q for exit\n";
    $sel->add($clnt);
    print "Got Connection from \"$host\" at port $port\n";
    }
    else {
    my $msgin=<$c>;
    chop($msgin);
    chop($msgin);
    if($msgin eq "q") {
    $sel->remove($c);
    $c->close; }

    else {
    foreach($sel->can_write()) {
    print $_ $msgin;}}
    }
    }}
    but whenever any client try to send a message it'll be broadcast,consider i want to get a message from the client#2 and send it to client#3 what should i do?
    i hope i make myself clear.
     
    Majid Dehghan, Nov 30, 2012
    #7
  8. Majid Dehghan

    Jim Gibson Guest

    In article <>,
    Majid Dehghan <> wrote:

    > much appreciated Jim Gibson,
    > but you see ("# Handle a connection. Register the new user, and broadcast a
    > message # to whoever is already connected.")
    > i don't want that,i just want to send a message from one user to only another
    > one,not all connected client.
    > i googled it too,but i need someone to guide me


    You need a way for clients to identify themselves to each other and to
    the server. Then, the client needs to specify to which other client his
    message will be sent. Then, instead of sending each incoming message to
    all clients, you send it to only the client specified by the sender.

    When a client connects, you should still probably send out a message to
    all clients informing them that a new client has joined the service, is
    ready to receive messages, and what their "handle" is. You will also
    have to send the new client the list of existing clients.

    --
    Jim Gibson
     
    Jim Gibson, Nov 30, 2012
    #8
  9. thanks Jim
    >You need a way for clients to identify themselves to each other and to

    the serve.

    could you be more specific,
    how to do that?
     
    Majid Dehghan, Nov 30, 2012
    #9
  10. Majid Dehghan

    Jim Gibson Guest

    In article <>,
    Majid Dehghan <> wrote:

    > thanks Jim
    > >You need a way for clients to identify themselves to each other and to

    > the serve.
    >
    > could you be more specific,
    > how to do that?


    That is up to you. Each client needs to have some short, text unique
    name by which to identify himself. I think you have two basic
    approaches:

    1. You assign each client a unique name when they connect.
    2. You allow each client to provide a name, then check to make sure
    that name is unique.

    The name must be known to all of the clients, so each client can decide
    to whom he is sending a message.

    Just how this is done depends upon the number of clients, how well they
    know each other, and how they normally identify themselves to each
    other. I have no idea what would be appropriate to your environment,
    and that is really outside the scope of this newsgroup.

    Once you have decided upon a scheme for uniquely identifying clients,
    then how to implement that scheme is within the scope of this
    newsgroup.

    Once you have a unique name for each client, you can use that name
    within your program as array elements or hash keys to maintain
    information about each client.

    --
    Jim Gibson
     
    Jim Gibson, Dec 3, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cameron Zemek

    non-blocking chat server

    Cameron Zemek, Jul 28, 2004, in forum: Java
    Replies:
    2
    Views:
    6,523
    Roedy Green
    Jul 28, 2004
  2. Sameer
    Replies:
    0
    Views:
    509
    Sameer
    Feb 13, 2005
  3. rkj
    Replies:
    2
    Views:
    640
    John C. Bollinger
    May 19, 2005
  4. Replies:
    0
    Views:
    2,240
  5. Larion
    Replies:
    1
    Views:
    1,903
    jcsnippets.atspace.com
    Mar 26, 2006
Loading...

Share This Page