开发者

Local Chat server in C using IPC

Hi Guys I need to write a chat server in C. It only need开发者_如何学运维s to use IPC.

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


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜