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

The Archive Base Latest Questions

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

I made a networked game in Java using Sockets. It works great, except… only

  • 0

I made a networked game in Java using Sockets. It works great, except… only through my LAN. :/ What I want to be able to do is set it up so that I can start the server running on my home computer and send the client code, in an executable jar, to someone else, and have them be able to launch it and connect through the internet. But like… I have no idea how to set up my modem & router for that. 🙁 I have a wireless Clear modem, for which the configuration page looks like this:

http://imageshack.us/photo/my-images/254/modem.jpg

And a Netgear router, whose page looks like this:

http://imageshack.us/photo/my-images/443/routerq.jpg

Right now, in the client and server runner classes, I pass my PC’s private IP address along with my chosen port number to the ServerSocket and Socket objects. I hear that Sockets are able to be either UDP or TCP, depending on how you set them up, or something…? I don’t do anything like that though, I just instantiate them and pass them the 2 values, and off they go…

In the code for the server:

ServerSocket sock = new ServerSocket();
sock.bind(new InetSocketAddress(IP, 9001));

Code for the client:

Socket sock = new Socket(IP, 9001);

So also, I would need to know how to change the code accordingly with the changes to my router/modem settings.

“IP” is a String representing my computer’s private IP, 192.168.1.10, and the program only works if that is the string I pass to the Socket & ServerSocket. Like I said, I have a modem which is connected to a router which is connected to my computer. So, can someone please explain to me (in detail, because I’m a noob) what exactly I would have to do to configure both of them, AND the changes I would have to make to my code?

  • 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-26T20:59:20+00:00Added an answer on May 26, 2026 at 8:59 pm

    It sounds like you’re asking a number of questions here… I’m no network/socket programming specialist, but here’s some ideas.

    For distribution, you may wish to look into Java Web Start. It’ll make it easy for your clients to obtain the app as well as automating updates.

    If you’re using the Socket constructor like that, the actual implementation will be a system default. You could override this by calling this method with a suitable SocketImplFactory implementation.

    As for the IP address and port… Using a hard-coded value for the port should be okay. You’ll need to decide on a port or at least some default anyway for clients to connect to. Even so, it might be useful to have the value read from some external configuration file. This’ll make it easier should you ever decide to distribute the server app to let other people run servers. They might want to use a different port.

    Having the server’s IP address (yours) hard-coded in code is definitely a no-no, though. Clients should connect using either an IP address or host name that they need to provide or set in some configuration file. A host name would be required if you don’t have a static IP address.

    Unless this is something for you and some friends to enjoy, where you can always just initiate a game by providing IP and port in a chat session or something, you’d be better off finding some external hosting solution at a company that takes care of the DNS resolution and network setup for you. These days you’ll find stuff like that pretty cheap if you don’t have requirements like a Java EE server or database.

    EDIT: thought of something else. TCP might be okay for your use-case, but if this is a game that requires minimal lag and quick input synchronization (like a shooter or fighting game) then it’s not the best choice. In that case UDP would be better. It would induce the requirement of adding some sort of detection for desync or a mechanism that makes up for any dropped packets.

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

Sidebar

Related Questions

I made a little chat applet using multicast. It works fine between computers on
I have made a simple server running locally using tcplisten and it works fine
I'm adding networked multiplayer to a game I've made. When the server sends an
Made this nice little loop for hiding and showing div's, works as a charm
I made a Java Applet with some Standard GUI Components on it. I used
I made a UIView using Interface Builder with a top bar that has Cancel
I made a simple pong game from a tutorial (icode blog)and would like to
I've made a simple dummy server/dummy client program using IOCP for some testing/profiling purpose.
I've got a little game that a friend and I are writing in Java.
I'm the network programmer on a school game project. We want to have up

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.