Making Http Simple Server With Java

by Son Rokhaniawan Perdata, S.T | 12:16 AM in , |

Praktikum's task Network and Apparatus Mathematics moves secondly be make one http simple server at localhost. With utilize SocketServer's function, therefore gets to be made one server which will wait “panggilan” on port 80 (HTTP). And will send html's code while called.

SocketServer works in one looping that perpetual to wait marks sense connection to go to port 80 on localhost. There is 4 constructor on SocketServer for example:

  1. public ServerSocket(int port) throws BindException, IOException
  2. public ServerSocket(int port, int queueLength) throws BindException, IOException
  3. public ServerSocket(int port, int queueLength, InetAddress bindAddress) throws IOException
  4. public ServerSocket( ) throws IOException // Java 1.4

n Java, to make one server gets to be done by trick as follows:

  1. One serverSocket a new one is made deep one given port (in this case port 80) utilizing constructor of one SocketServer.
  2. Then serverSocket waits until mark sense coming connection through port has already is determined previous utilize accept's function().
  3. Then depends from server type, well utilize getInputStream's function(), getOutputStream's function(), or both of ala function goes together to get input and output stream in order to gets communication with client.
  4. Server and client gets communication / get interaction until its time hang up connection.
  5. Server, Client or both hangs up connection
  6. Server returns to to step 2 and waiting until marks sense succeeding connections.

And attachment source's following code that I takes from praktikum's module meagrely modifies to be able to qualify as one http server.

Serverku.java

Related Posts by Categories



2 comments:

  1. d3ptzz on March 27, 2009 at 11:46 PM

    woh... lha ini....


    kok ngambil tanpa ijin???

     
  2. d3ptzz on March 27, 2009 at 11:48 PM

    postingan asli di : http://d3ptzz.kandangbuaya.com/2008/02/27/membuat-sebuah-http-server-sederhana-dengan-java/

     

About Me

My photo
I am its person simple. Bad blood platitude. Directly az goes to aim target

Shoutbox