dfischer.femtowebserver.adapter
Class HttpdSocketConnectionAdapter
java.lang.Object
|
+--dfischer.femtowebserver.adapter.HttpdSocketConnectionAdapter
- All Implemented Interfaces:
- HttpdConnectionAdapterInterface
- public class HttpdSocketConnectionAdapter
- extends java.lang.Object
- implements HttpdConnectionAdapterInterface
Supports the plain TCP/IP protocol and is the default
adapter used by Httpd.
Sourcecode of Adapter:
import java.net.*;
import dfischer.femtowebserver.httpd.*;
public class HttpdSocketConnectionAdapter implements HttpdConnectionAdapterInterface
{
private ServerSocket serverSocket = null;
public void init(HttpdProperties httpdProperties) throws Exception
{
// create new server socket
serverSocket = new ServerSocket(httpdProperties.getServerPort(), 50, httpdProperties.getBindAddress());
serverSocket.setSoTimeout(1000);
}
public HttpdConnection getNextConnection(HttpdProperties httpdProperties) throws Exception
{
// accept new client connection
Socket clientSocket = serverSocket.accept();
clientSocket.setSoTimeout((httpdProperties.getRequestTimeout() + 10) * 1000);
// transfer client connection to Httpd
HttpdSocketConnection httpdSocketConnection = new HttpdSocketConnection(clientSocket, "http");
return httpdSocketConnection;
}
public void shutdown(HttpdProperties httpdProperties) throws Exception
{
// close server socket
serverSocket.close();
}
}
- See Also:
Httpd.setConnectionAdapterClass(java.lang.String),
HttpdConnectionAdapterInterface,
HttpdConnection,
HttpdSocketConnection
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
HttpdSocketConnectionAdapter
public HttpdSocketConnectionAdapter()
init
public void init(HttpdProperties httpdProperties)
throws java.lang.Exception
- Description copied from interface:
HttpdConnectionAdapterInterface
- Initializes the connection adapter. Called by the Femto Web Server main thread Httpd only once when it is started.
- Specified by:
init in interface HttpdConnectionAdapterInterface
- Following copied from interface:
dfischer.femtowebserver.httpd.HttpdConnectionAdapterInterface
- Parameters:
httpdProperties - read/only access to the Femto Web Server configuration
getNextConnection
public HttpdConnection getNextConnection(HttpdProperties httpdProperties)
throws java.lang.Exception
- Description copied from interface:
HttpdConnectionAdapterInterface
- Listens for a new client connection and blocks until a new client connection is made.
The Femto Web Server calls this method as often as it's possible in an endless loop.
As result a network protocol independent HttpdConnection is given back to the Femto Web Server which
is used to process the HTTP request.
From time to time (1..60 seconds) it would be fine that a java.io.InterruptedIOException is thrown by this method.
Optionally throwing the InterruptedIOException will not abort the Httpd main thread, but enables
the Femto Web Sever to do a graceful shutdown if Httpd.shutdown() is called.
- Specified by:
getNextConnection in interface HttpdConnectionAdapterInterface
- Following copied from interface:
dfischer.femtowebserver.httpd.HttpdConnectionAdapterInterface
- Parameters:
httpdProperties - read/only access to the Femto Web Server configuration- Returns:
- the new client connection (network protocol independment).
- See Also:
HttpdConnection,
Httpd.shutdown(),
Httpd.setConnectionAdapterClass(java.lang.String)
shutdown
public void shutdown(HttpdProperties httpdProperties)
throws java.lang.Exception
- Description copied from interface:
HttpdConnectionAdapterInterface
- Closes the connection adapter. Called from the Femto Web Server main thread only once when
Httpd.shutdown() was called.
- Specified by:
shutdown in interface HttpdConnectionAdapterInterface
- Following copied from interface:
dfischer.femtowebserver.httpd.HttpdConnectionAdapterInterface
- Parameters:
httpdProperties - read/only access to the Femto Web Server configuration- See Also:
Httpd.shutdown()
Copyright 2002, 2003, 2006 by Ingenieurbüro David Fischer GmbH, Switzerland. All rights reserved.