Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6027077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:32:18+00:00 2026-05-23T04:32:18+00:00

I’m trying to connect from a standalone applet to a servlet running on tomcat:

  • 0

I’m trying to connect from a standalone applet to a servlet running on tomcat:

Servlet

public void init(ServletConfig config) throws ServletException { 
    super.init(config);
    // Start a daemon thread 
    try { 
        daemonThread = new Daemon(this);
        daemonThread.start();
    }
    catch (Exception e) { 
    }
}

protected int getSocketPort() { 
    return 8080;
}

public void handleClient(Socket client){ 
    new ScribbleThread(this, client).start();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    StringBuffer sb = new StringBuffer();
    sb.append("<html><body bgcolor=pink text=red>");
    sb.append("<h1 align=center>RUNNING</h1><hr>");
    sb.append("</body></html>");
    out.println(sb);
    out.close();
}
}

Servlet’s init() creates this:

class Daemon extends Thread { 
private ServerSocket serverSocket;
private SocketServlet servlet;

public Daemon(SocketServlet servlet) { 
this.servlet = servlet;
}

public void run() { 
    try { 
        // Create a server socket to accept connections 
        serverSocket = new ServerSocket(servlet.getSocketPort());
    }
    catch (Exception e) { 
        return;
    }
    try { 
        while (true) { 
            try { 
                servlet.handleClient(serverSocket.accept());
            }
            catch (IOException ioe) { 
            }
        }
    }

I have this deployed by eclipse to TomCat. My question is what address does my applet need to make the socket to? When i visit http://localhost:8080/scrabServ/connect I see the ‘RUNNING’ message from the doGet() so is that where it needs to point?

Applet:

public static String testConnection(){
    InputStream in = null; 
    try { 
        // Make socket connection to servlet
        String servlet = new String("localhost/scrabServ/connect");
        Socket socket = new Socket(servlet, 8080); 

this gives me:

Exception in testConnection()java.net.UnknownHostException: localhost/scrabServ/connect
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at scribble.Scribble.testConnection(Scribble.java:41)
at scribble.Scribble.main(Scribble.java:28)

and points to the new Socket(servlet, 8080) line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:32:18+00:00Added an answer on May 23, 2026 at 4:32 am

    You would have only to open a socket to "localhost", 8080 and then issue a GET scrabServ/connect command. You can’t open a socket to a specific URL.

    To communicate with a servlet you do it via request parameters, basically issuing a GET command such as: http://www.jmarshall.com/easy/http/http_footnotes.html#getsubmit

    Maybe you should use URLConnection instead. If you detail what exactly you want to do, maybe I can have a better idea of how to help you, maybe a HTTP server is not even needed for what you want to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.