Trying To Implement Concurrent TCP Server and Client in c

风流意气都作罢 提交于 2020-01-03 04:52:09

问题


I have implemented TCp concurrent server and client in c using threads as well as forks. But I don't have any way to check whether there is any other standard way of implementing this.

I have goggled for standard coding stuff but didnt find anything useful. Can someone pl z share some good links or code so that I can have a standard idea of implementing Concurrent servers.

Thanks for help


回答1:


There's no "standard idea". Your approach is going to depend on requirements, performance, scalability, and amount of time allowed for development.

  • One thread per client
    • Possibly with a threadpool
  • Multi-threaded pipeline model, with N workers
  • One thread per server, using poll/select
  • One thread per server, event-based with callbacks
  • Forking children, one per client connection
    • pre-forking children, e.g. Apache web server

Etc. All of these have their uses.




回答2:


Some good links for you:

  • Beej's Guide to Network Programming will help you get the basics down,
  • The C10K problem will give you an overview of the design landscape,
  • High-Performance Server Architecture will make you re-think the "standard" approaches.

Hope this helps.




回答3:


Concurrent servers (as long as they are quite simple, and performance is not much of an issue) are often created with poll() or select(). Now, this is assuming you are on *nix. If you can use C++, the boost libraries have ASIO , which is a cross-platform library that allows you to write once and compile everywhere. There isn't really a standard way to do things since the ideas vary from OS to OS.



来源:https://stackoverflow.com/questions/5290860/trying-to-implement-concurrent-tcp-server-and-client-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!