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?