Results 1 to 2 of 2
  1. #1
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Multiplayer in localhost

    I have downloaded XAMPP and I use localhost.

    Can I make my program accessible for someone who isnt using my network?

    I mean : other user from diffrend city, could connect to my program and use it?

    Java Code:
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.input.KeyCode;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage;
    
    public class JAVAXx extends Application {
    	
    	 int x = 0;
    	 int y = 100;
        
    	@Override
        public void start(Stage primaryStage) 
        {   		
    
         Rectangle myHero = new Rectangle (50,50);
         myHero.setTranslateY(100);
         
      	 	  	  	
    	 Group multipleComponents = new Group();	
    	 multipleComponents.getChildren().addAll(myHero);     
    
          
         Scene scene = new Scene(multipleComponents, 600, 400);
         primaryStage.setScene(scene);
         primaryStage.show();
         
         scene.setOnKeyPressed(e -> {
        	    if (e.getCode() == KeyCode.W) 
        	    {
        	    	y -= 20;
        	        myHero.setTranslateY(y); 
        	    }
        	    if (e.getCode() == KeyCode.S) 
     	    	{
     	    		y += 20;
     	    		myHero.setTranslateY(y);  
     	    	}
        	    if (e.getCode() == KeyCode.A) 
     	    	{
        	    	x -= 20;
        	    	myHero.setTranslateX(x);   
     	    	}
        	    if (e.getCode() == KeyCode.D) 
     	    	{
        	    	 x += 20;
        	    	 myHero.setTranslateX(x);    
     	    	}
        	});
    
        }
            
        public static void main(String[] args) 
        {
            launch(args);
        }
    }
    This is small example of moving around rectangle with WASD. So I wish that I would I could click W and S, while other user could click A and D.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,189
    Rep Power
    12

    Default Re: Multiplayer in localhost

    The localhost address is simply the loopback address of the PC one is using. So it doesn't make sense to me to have some access
    that address from outside. But I am not familiar with the app and how its used. normally, to let someone access your laptop remotely
    you need to:

    1. Provide them the ISP side address of your LAN.
    2. Ensure any required ports are not blocked by your router or ISP.
    3. Ensure the PC is listening for incoming traffic on that port.
    4. And you will need to direct traffic for the specific port to a specific IP address since otherwise the
    router will not know to which IP to forward the traffic.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. 2D Multiplayer
    By AlexGraal in forum Java Gaming
    Replies: 4
    Last Post: 04-30-2014, 09:28 AM
  2. multiplayer LAN game
    By ethomas92 in forum Networking
    Replies: 1
    Last Post: 12-14-2012, 08:54 PM
  3. Multiplayer (one on one) how is it done?
    By überfuzz in forum Android
    Replies: 0
    Last Post: 07-18-2011, 11:00 AM
  4. Multiplayer Bingo game
    By js4learn in forum Java Gaming
    Replies: 1
    Last Post: 07-08-2011, 03:43 AM
  5. Multiplayer lobby
    By OrangeDog in forum Advanced Java
    Replies: 6
    Last Post: 09-30-2009, 08:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •