Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl chat server

Reply
Thread Tools

perl chat server

 
 
Majid Dehghan
Guest
Posts: n/a
 
      11-30-2012
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.
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      11-30-2012
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
 
Reply With Quote
 
 
 
 
Majid Dehghan
Guest
Posts: n/a
 
      11-30-2012
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
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      11-30-2012
In article <63546c91-2ee5-4960-9bd7->,
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
 
Reply With Quote
 
Majid Dehghan
Guest
Posts: n/a
 
      11-30-2012
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

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      11-30-2012
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
 
Reply With Quote
 
Majid Dehghan
Guest
Posts: n/a
 
      11-30-2012
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,Liste n=>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.
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      11-30-2012
In article <ce6b7a31-b156-4ec6-a33a->,
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
 
Reply With Quote
 
Majid Dehghan
Guest
Posts: n/a
 
      11-30-2012
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?
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      12-03-2012
In article <fc76051a-6479-4dc4-936f->,
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build a simple Textual Chat with Java - 2 Clients and 1 Server: Help Me !! Larion Java 1 03-26-2006 06:48 PM
Chat Server and Chat Client for INTRANET diptanu@gmail.com Java 0 01-30-2006 06:56 PM
how to connect a chat applet to the server rkj Java 2 05-19-2005 05:48 PM
About Polling Chat Server (Personal Chatting) Sameer Java 0 02-13-2005 05:27 PM
non-blocking chat server Cameron Zemek Java 2 07-28-2004 07:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57