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 6777501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:09:20+00:00 2026-05-26T16:09:20+00:00

Playing with a few tutorials on sockets but struggling to connect. My tomcat server

  • 0

Playing with a few tutorials on sockets but struggling to connect.

My tomcat server is at eric.server.com and is running a ajp connector on port 8052.

I want to use the knock knock java tutorial to connect. I’ve uploaded the KnockKnockProtocol.class and KnockKnockServer.class to eric.server.com/apps/knock

On the tutorial it shows this:

kkSocket = new Socket("tarranis", 4444);

Which I have changed to:

kkSocket = new Socket("eric.server.com/apps/knock", 8052);

I then run the client program from eclipse but I just get the UnknownHostException.

Could someone please explain what I’m doing wrong, totally new to Tomcat and servlets in general?

TIA

import java.io.;
import java.net.
;

public class KnockKnockClient {
public static void main(String[] args) throws IOException {

    Socket kkSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    try {
        kkSocket = new Socket("eric.server.com", 8052);
        out = new PrintWriter(kkSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
    } catch (UnknownHostException e) {
        System.err.println("Don't know about host.");
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Couldn't get I/O for the connection to.");
        System.exit(1);
    }

    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    String fromServer;
    String fromUser;

    while ((fromServer = in.readLine()) != null) {
        System.out.println("Server: " + fromServer);
        if (fromServer.equals("Bye."))
            break;

        fromUser = stdIn.readLine();
    if (fromUser != null) {
            System.out.println("Client: " + fromUser);
            out.println(fromUser);
    }
    }

    out.close();
    in.close();
    stdIn.close();
    kkSocket.close();
}

}

  • 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-26T16:09:20+00:00Added an answer on May 26, 2026 at 4:09 pm

    You are using a host name of “eric.server.com/apps/knock”, when what you really want is “eric.server.com”.

    Then once you have connected, you can then start engaging in the socket’s protocol (ajp) to communicate with it. The URI portion goes in the req_uri portion of the protocol, not in the host.

    But the bigger issue is that Tomcat is really an HTTP server, not a socket server. You should either write a servlet that implements the server portion of the tutorial and run that in Tomcat, or just write it as a standalone server process.

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

Sidebar

Related Questions

I'm playing around with get_iplayer (fantastic) it's running every few hours to grab any
I was playing around with Python's subprocess module, trying a few examples but I
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into
I'm just playing with jqplot for a few hours but I couldn't find how
I'm running through a few tutorials that describe ways of applying custom images to
A few years ago we started playing around with XForms from the W3C for
Update: After playing around with this for a few hours, went with a multi-query
I'm playing with ASP.NET MVC for the last few days and was able to
I've been playing around with Qt for a few hours now. I found that
Alright, so after a few hours of me playing around to no avail, I

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.