Response adapter.

Architect's Corner
Servlet adapters can solve your socket problems
by Andrei Nazariev
Listing 5. Response adapter.

public class ResponseAdapter extends HttpServlet implements
SingleThreadModel {
  final static String SVR_ADDRESS = "localhost";
  final static int    RES_PORT = 2051;

  public void doGet(HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException {
    OutputStream toClient = res.getOutputStream();
    InputStream fromServer = new Socket(SVR_ADDRESS, RES_PORT).getInputStream();
    byte[] buffer = new byte[256];
    try {
      while(true) {
        toClient.write(buffer, 0,;
    }catch(IOException e) { e.printStackTrace(); }

About the Author

Andrei Nazariev is a senior Java architect at Sun Microsystems' Sun Java Center in Orlando, FL. He can be contacted at


Most   Popular
Upcoming Events


Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.