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

  • Home
  • SEARCH
  • 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 8808055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:31:25+00:00 2026-06-14T02:31:25+00:00

Im trying to make a server out of my computer so that clients from

  • 0

Im trying to make a server out of my computer so that clients from their computers can connect and communicate with my computer. I made the server on port 31350 and the client is trying to connect through my router’s ip address. But it only works through lan when I have “localhost” or the name of my computer in the parameters for the socket creation. and not when I use my ip address, running the client and server on different networks. Here is the code.

Here is the server that my computer is running.

public static void main (String[] args) throws IOException
{
    ServerSocket server = new ServerSocket(31350);
    Socket client1 = server.accept();   
}

Here is the client code that my friend is running on his computer

public static void main(String[] args) throws IOException, UnknownHostException
{
    Socket socket;

    //  #'s are what I got from whatismyip.org on the server computer)
    byte[] serverb = new byte[] {(byte)##, (byte)##, (byte)###, (byte)###};

    socket = new Socket(InetAddress.getByAddress(serverb),31350);
}

This is what it says when I run the client

Exception in thread “main” java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.(Socket.java:425)
at java.net.Socket.(Socket.java:241)
at ClientTest.main(ClientTest.java:22) // 22 is the line socket = new Socket(InetAddress.getByAddress(serverb),31350);

firewalls are disabled. the port 31350 on my router is forwarded to my computer’s local ip address that I got from using ipconfig in cmd. But it still doesnt work, I just get IOException when trying to create the socket from the client computer. Nothing happens on the server computer. What’s wrong?

  • 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-14T02:31:26+00:00Added an answer on June 14, 2026 at 2:31 am

    [update]

    As you might expect, connection timed out indicates it’s some kind of a network problem. The packets from your client are not arriving at the server machine. The exact solution will depend on the type of router, but the term to google for is “port forwarding”. Here is an article I found at random that might help: http://www.rhinosoft.com/KnowledgeBase/kbarticle.asp?RefNo=1289

    Basically you program the router so that any connection request at port 31350 will be forwarded to your computer on the lan at it’s local IP address.

    Good luck!

    [original comment]

    This is more of a comment than an answer (but I needed the extra room). Your try catch logic is going to make it much more difficult to diagnose the problem. Simplify the code as follows:

    public static void main(String[] args) throws IOException, UnknownHostException
    {
        Socket socket;
    
                //  #'s are what I got from whatismyip.org on the server computer)
        byte[] serverb = new byte[] {(byte)##, (byte)##, (byte)###, (byte)###};
    
        socket = new Socket(InetAddress.getByAddress(serverb),31350);
    }
    

    Just let the original IOException propagate and update your question to include the exception stack trace. The original exception contains valuable information – if it says connection refused it means one thing – perhaps your port number is incorrect. If it says connection timed out it means something else – either you really do have a firewall problem or perhaps your ip address is wrong.

    Your code is catching the useful exception, swallowing it and throwing a much less useful exception.

    Do the same thing to your server code:

    public static void main (String[] args) throws IOException
    {
        ServerSocket server = new ServerSocket(31350);
        Socket client1 = client1 = server.accept();
    }
    

    The stack trace will show which method threw the exception so you don’t need redundant text like InetAddress creation failed

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

Sidebar

Related Questions

I'm trying to make a server that can be connected to by multiple clients.
I'm trying to make a simple HTML server that will read a request from
I am trying to make a proxy server that gets a page from www.xxx.com
I am trying to make a server-client model in which the server can see
I am trying to make a socket.io based server but whenever I connect by
I'm trying to make a call that might throw an exception due to server
I'm trying to make a basic datagram client/server program with Java. I've made the
I am trying to make a socket server that spews mouse move events, in
I trying to make the AJAX request time-out if the web server goes down.
I'm trying to make a small testing server for Bugzilla so I can test

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.