title: Java Sockets work over LAN but not Internet?
body: <p>Hello I am making a Java multiplayer game and everything works fine.
  It has all someone would need but I found a problem, it uses ServerSocket for server, and Socket for clients, works fine but the big problem is that it doesn't work over worldwide. Only LAN, I even tried Hamachi but that didn't work, too.</p>
  
  <p>Do you have any ideas what would work?</p>
  
  <p>Some more info: I use a specific thread in server for accepting, sending and receiving sockets and also specific thread in client for sending and receiving. It sends an object which I made and contains all information.</p>
  
  <pre><code>ip = InetAddress.getLocalHost().getHostAddress() + ":" + port;
  
  server = new ServerSocket();
  
  //This asks you if you want to use a specific IP or just the one that we got in first line
  String socketaddress;
  socketaddress = (String) JOptionPane.showInputDialog(null, "IP: ", "Info",JOptionPane.INFORMATION_MESSAGE,null,null,InetAddress.getLocalHost().getHostAddress());
  server.bind(new InetSocketAddress(socketaddress, port));
  
  //Here it starts the accept thread, and then it starts send and receive threads
  new Thread(accept).start();
  </code></pre>
  
  <p>Here is stuff from client that I find most important:</p>
  
  <pre><code>socket = new Socket(ip,port);
  
  String set_username = System.getProperty("user.name");
  set_username = (String) JOptionPane.showInputDialog(null, "Username: ", "Info", JOptionPane.INFORMATION_MESSAGE,null,null,set_username);
  username = set_username;
  
  //It sends the username to server
  ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
  oos.writeObject(username);
  
  //Then server responds with a message
  ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
  String response = (String) ois.readObject();
  
  //This writes the server' message   
  JOptionPane.showMessageDialog(null, response, "Message",JOptionPane.INFORMATION_MESSAGE);
  </code></pre>
  
  <p>Also I have another problem, the sockets take like 3 or 4 seconds to get from 1 client to another and it should be almost instant because it's on same network and I have a fast internet.</p>
  
  <p>EDIT:
  I tried creating a server on same pc with client and then when joining using my global IP, it didn't work :(</p>
  
  <p>EDIT:
  ITS WORKING IM SO HAPPY RIGHT NOW ALL I HAD TO DO IS ADD PORTS IN FIREWALL THANK YOU SO MUCH GUYS :D. NOW I CAN PLAY WITH MY FRIENDS :3</p>