simple chat program

James Laver james.laver at gmail.com
Mon Mar 10 15:39:11 GMT 2008


On 3/10/08, Hemant Verma <Hemant.Verma at ons.gsi.gov.uk> wrote:
> Hi,
>
> I am writing a simple chat program using sockets and client server. I am
> able to send information between client and server.
> Would any body please let me know how I can send information from Client1
> to Client2 using same server.
>
> Thanks & Regards,
> Hemant Verma
> Xansa, A Steria Company
> Office for National Statistics, Southampton.
> Mob: 07715759776, Direct CUG: 8889776
> Ext: 0132-981-3575
>
>
> For the latest data on the economy and society consult National Statistics at http://www.statistics.gov.uk
>
> *********************************************************************************
>
>
> Please Note:  Incoming and outgoing email messages are routinely monitored for compliance with our policy on the use of electronic communications
> *********************************************************************************
>
>
> Legal Disclaimer  :  Any views expressed by the sender of this message are not necessarily those of the Office for National Statistics
> *********************************************************************************
>
>
> The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by Cable&Wireless in partnership with MessageLabs. (CCTM Certificate Number 2007/11/0032.) On leaving the GSi this email was certified virus free.
> Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes.
>

Your server would need to keep a connection pool to all of its clients.
Something like this:
1. C1 connects to server and registers itself as 'client1' (you could
store these ids in a hash with the values being sockets).
2. C2 connects to the server and registers itself as 'client2'
3. C1 sends a request such as 'send client2 <data>'.
4. Server looks up client2 in the hashtable and sends that data
through that socket

I recommend you come up with some sort of regular structure for
commands through the sockets, whether that be XML (*spit*) or a binary
format (pack?) or YAML or something. This will allow you to parse
things much more easily (and make excellent use of CPAN)

Regards,
--James

--
TCPA WILL TAKE AWAY YOUR COMPUTER RIGHTS :http://www.againsttcpa.com/index.shtml


More information about the london.pm mailing list