tags:

views:

438

answers:

1

Hi Guys I need to write a chat server in C. It only needs to use IPC.

Could you help me on how to proceed on this. A skeleton code will help me a lot.

+2  A: 
  1. Write an echo server: a server that accepts one client, and repeats everything the client says back to it.

  2. Expand this server to support multiple simultaneous connections.

  3. Have the server echo to all connections.

  4. Consider as commands some pattern of lines from clients -- an initial "/", say, and act on them (close the connection, name the connection, list connections, etc.) rather than echo them.

  5. Prefix all echo'd text with the name of the client, with a default "Anonymous$N" and then the name set by a command from #4.

  6. When receiving a new connection, have the server elicit a name from it before the server begins echoing text from it and acting on other commands.

And so on. As mentioned, Beej's Guide can help you get past #1 and #2.

EDIT: OK, you added the 'IPC' language. You can still use sockets for this over the loopback device, unless you've some special requirement that you think IPC covers. You can also use UNIX domain sockets - named pipes. perlipc discusses them with a short example, and you can continue to e.g. the GNU C library manual.

ayrnieu
I need to use message queues to implement this.
Alex Xander
OK. Beej's guide: http://www.ecst.csuchico.edu/~beej/guide/ipc/mq.html
ayrnieu