简体   繁体   中英

How to implement a multithreaded web server in Java

My assignment is to implement a multithreaded web server in Java but i have no idea where to start. All we've seen in the lectures is how tcp works,layers etc.but i have no idea about how to implement a web server.

Can you give me a starting point?

First of all, you have to make choice about the programming language you want use. Several languages are particulary useful and more adapted for network programming. I thinking about Erlang for example.

You haven't mention which language should you use. I assumed C/C++.

First, you can look at Boost.Asio library an it's examples . There are two HTTP server examples.

Second, if you need a rough plan on what to do here it is:

  1. Create socket, bind() it on needed address (0.0.0.0 for example), run listen() on it and get ready to accept() connections.
  2. After accepting new connection, you can recv() data from it, which would be plain text accorfing to HTTP protocol.
  3. After determining what client wants you should make up buffer and send() it back.

Exact function names and overall details are dependent on your programming language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM