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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:48:45+00:00 2026-06-04T16:48:45+00:00

How do i go about making my Java app run an HTTP server on

  • 0

How do i go about making my Java app run an HTTP server on some socket (e.g 172.16.1.10:8080) and make it so that when another computer on the network connects to a domain (e.g http://myjavadomain.com) it gets redirected to the socket?

  • 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-06-04T16:48:47+00:00Added an answer on June 4, 2026 at 4:48 pm

    If you want to run a fully fledged HTTP server then you will probably want to use some external library. For instance, Tomcat is written in Java, but there is also SUN’s httpserver package. If it’s just a simple socket server you’re after, you can use the built-in classes from the java.net package:

    ServerSocket server = new ServerSocket(8080);
    
    while (running) {
        Socket socket = server.accept();
        handleConnection(socket);
    }
    

    This will listen for incoming socket connections on port 8080 and create a new Socket whenever a client connects. You can then communicate with the client through the Socket‘s InputStream and OuputStream, which you would probably do in a separate Thread, so that your ServerSocket can continue listening for incoming connections from other clients.

    As for the second part of your question: by default, a web browser will connect to port 80, and there are several ways you could do port forwarding. One possible solution using iptables is given on this website:

    iptables -t nat -I PREROUTING --src 0/0 --dst 172.16.1.10 -p tcp --dport 80 -j REDIRECT --to-ports 8080
    

    But the easiest solution would be to just specify the port number directly when connecting to your machine, e.g.

    http://myjavadomain.com:8080
    

    This is assuming that your DNS is configured so that it resolves myjavadomain.com to 172.16.1.10 already.

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

Sidebar

Related Questions

How do I go about making a socket policy file server in C#. All
How would I go about making a function that would do this in java.
I learnt about prepared statements when making a JDBC-enabled Java application, and my app
What is the best way to go about making an app that does the
I'm thinking about making an application that makes audio in a Java application. The
i've been making an app for android in java, but i'm curious about convering
In the effort to learn more about applets and Java, I am experimenting making
I need information about making installation packages for Linux. I want to make simple
How would i go about making an animation of a rocket move to another
I need to make a web app that I would be able to install

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.