Server/client chat application
#1 Members - Reputation: 324
Posted 26 November 2012 - 01:01 PM
Now to the problem. I'm not sure which way is the easiest/best way to implement this. For the chat room I thought of when a user writes something, the message is sent to the server and the server then echoes that message to the other clients. Not sure what other options I have. Also some ideas on how to implement the private messaging between clients in a chat room would be great.
I am using C++ and unix sockets.
#2 Moderators - Reputation: 3371
Posted 26 November 2012 - 02:02 PM
#4 Moderators - Reputation: 8468
Posted 26 November 2012 - 04:03 PM
You then have headers saying join channel, part channel, ping, set nickname, and so on.
join channelname
part channelname
ping username
MsgFrom channelname textOfMessage
#5 Members - Reputation: 324
Posted 26 November 2012 - 04:24 PM
Instead of directly echoing the data you receive, you'll need to process it as headers and payloads.
You then have headers saying join channel, part channel, ping, set nickname, and so on.
join channelname
part channelname
ping username
MsgFrom channelname textOfMessage
Could you elaborate? Not sure what you mean.
#6 Moderators - Reputation: 8468
Posted 26 November 2012 - 05:05 PM
Let's run through a quick IRC-like system.
You connect.
You want to log in, so you send:
SEND: NICK frob
You get back: OK
You want to join a chat room named #foo:
SEND: JOIN #foo
You get back: RPL_TOPIC #foo This is the topic of Channel #foo
You also want to join a chat room named #bar:
SEND: JOIN #bar
You get back: RPL_TOPIC #bar This is the topic for Channel #bar
Suddenly you get a message:
:#bar RobotAtBar Welcome to channel #bar! Visit our web site for the rules.
That tells you which channel it is from, which user it is from, and the message to display.
Now you want to send a message to channel #foo
Send: #foo Hi everybody!
to which you may get this response: #foo frob Hi everybody!
And so on.
Edited by frob, 26 November 2012 - 05:06 PM.
#7 Members - Reputation: 324
Posted 27 November 2012 - 04:47 PM
I wanna know how the server and clients should communicate. For example, if 3 clients are connected to a chat room and client 1 types something, how is client 2 and 3 supposed to know what client 1 wrote? Does client 1 write the message to the server which then forwards that message to client 2 and 3? Or what approach is the best for this kinda situation? This is what i'm confused about.
#8 Moderators - Reputation: 8468
Posted 27 November 2012 - 05:14 PM
It is a star architecture.
When someone in a chat room sends a message to the server, the server needs to identify those in the room and send the message out to each of them.
#9 Members - Reputation: 324
Posted 27 November 2012 - 05:31 PM
Say 3 clients is connected to a chat room. Client 1 want to be able to only talk with client 2. Do the messages between client 1 and 2 also go through the server, or is a separate connection between client 1 and 2 established?






