Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Program to launch and mirror another program

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Program to launch and mirror another program

    Hi everyone. I was hoping to get a few pointers in the right direction.. not necessarily any specific code. I'm trying to create a program that would basically launch one and that would also create two more instances of that program, without their GUI preferably, but that would mirror my keyboard commands and and mouse click commands from the primary instance to each of the non-shown instances. So basically, if I were to do something in my main program, the exact same thing would be done in two separate instances of the same program.

    I'm kind of lost on how to make that happen. Thanks for any help you can offer.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Program to launch and mirror another program

    Why do you need to invoke the two hidden instances of the application?

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    They don't necessarily have to be hidden instances, but because the purpose of the program will be to make them do the same as the visible instance, there shouldn't be any need for them to be visible.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Program to launch and mirror another program

    ...why do you need to do this? There might be a better way to accomplish your end goal.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Program to launch and mirror another program

    You didn't tell, what exactly do you want to achieve. May be there are many other solutions of your problem.

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    I'm playing an asteroids mining game and I want to run 3 of them at the same time.. That way I can have 3 guys mining an asteroid while only having to control one of them.

    The game launches and you load a character and then move your guy around and mine asteroids and collect objects and sell them.

    I used to have a program a friend wrote for me in Delphi that did the same thing, but I've since lost it, and now that I am a CS student studying java I want to learn how to actually write one myself.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Program to launch and mirror another program

    As far as i understood as per your description, you need to let three players lie mines while controlling one and other two will be random, right?

  8. #8
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    Not exactly, but kind of. So it should work something like this.

    Three players: Char A, Char B, Char C.

    The way the game works is you launch the application, select your character and play. All characters can share the same space and mine the same asteroid. The idea of having all three of them do it is to speed the process up. Three doing the same thing instead of one. But I can't have the other two be random, I need to have them do whatever the first one is. Under normal circumstances, I could just launch three instances of the program, manually select each character and go about doing the same thing, but then I'd have to manually control all three characters.

    What I'd like to do, and the way the other program I had worked is like this:

    Launch multitasking app (the one I'm trying to write) and then select which character will be Char A. Then select which characters will be B and C.

    Launch active game application with Char A and play normally. Simultaneously, launch two additional hidden instances of the same application AS Char B and Char C.

    Now all three characters are in the game at the same point. What I want to have happen is have all of Char B and Char C's actions match what is actively done in the GUI as Char A. So if Char A moves left, so do B & C. If Char A mines an Asteroid, B & C do also. If A sells mined ore, so do B & C, etc.

    The game is tile based, so you move by clicking which tile to move to.. So theoretically, all movements should be the same .

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Program to launch and mirror another program

    Take a look at the Robot class.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    My understanding of the robot class was that it actively controls your mouse or keyboard, but doesn't just mimic your movements right? Like, I could have a robot class click a button at position x,y, but I couldn't simultaneously click that button in another location on a different instance? Robots are pre-programmed right? So it would only handle pre-programmed movements? Like robot.keypressed(VK_SPACE) or something like that.

    What I'm trying to do is kind of like multiboxing / dualboxing.

    Is there some way to launch the application and "listen" for commands it sends? For instance.. when I want to shoot an asteroid, I click that asteroid, and it is selected or targeted. Then I click the command to shoot it. So is there any way to "listen" for some command like "asteroid13.isSelected" or something like that, and then use a generic form of that in my program? Probably not.. I think I'm getting ahead of myself. I don't really know enough about it I think. I mean, I know that the client program sends some sort of command to the server application that says I have targeted a specific asteroid, or that I have engaged it, but I don't know if there is anyway to figure out what that specific command is, and emulate it with a separate program.

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Program to launch and mirror another program

    Okay, I finally see what you're saying. Depending on what exactly the actions are, you could pull this off using the Robot class, but it's going to get complicated if you're doing any non-trvial actions (Just clicking? Dragging? Keyboard commands? Combinations?).

    Are you trying to do this with an existing game/program? Or are you trying to create a game from scratch that would contain this behavior?

    If the former, you might be out of luck. This is exactly the kind of thing that most game designers make difficult, for valid reasons.

    If the latter, you have access to the code, so you'd simply implement some kind of communication interface where one game told the other instances of the game what was happening.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    This is for an existing game. I know that it is possible, I'm just not sure how. As I mentioned, a friend of mine made a program a few years ago that did the same thing, but I have since lost that program, and don't know how it worked. I'm not sure how the robot class would work.

    I launch and control Instance A of the program normally. What I'm trying to do is to simultaneously launch Instance B and Instance C of the same program (hidden or otherwise) and simply repeat each action I perform in Instance A. So I imagine (although I'm sure I'm wrong) it works something like this in pseudo-code..

    Launch Instance A of program and login as Character A. GUI opens normally and operates normally.

    At the same time, launch Instance B to log in as Character B and Instance C to log into Character C. Now all three characters are logged in in separate instances, and in game at the same location.

    Now Instance B and C just 'listen' for actions performed by me manually in Instance A, and repeat them. So if I make Char A move to Node 25, B and C move to Node 25. If I make Char A target Asteroid 13, B and C also target Asteroid 13.

    This of course assumes that at some point my client program sends certain actions that can be 'repeated' for B and C. When I click a specific node or tile in game, it sends a command to the server to 'update my location' to that specific node. I just don't know what that command is. Not sure if there is anyway to find it either.

  13. #13
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program to launch and mirror another program

    Ok, after talking to said friend who wrote the original program, I've learned how he did it (although not how to do it again, which is what I'm after).

    Basically, he created a new socket connections to the server for the cloned characters, and logged in Chars B and C in through those sockets. Then he just copied all traffic from the socket that corresponds to the main user-controlled program to sockets B and C. So it doesn't really matter what command is sent, if A sends it, B and C send it.

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Program to launch and mirror another program

    Lesson: All About Sockets (The Java™ Tutorials > Custom Networking)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] How to write Eclipse launch file?
    By beruska in forum Java IDEs
    Replies: 3
    Last Post: October 18th, 2011, 09:41 AM
  2. method to launch a jar file
    By frozen java in forum Java Theory & Questions
    Replies: 2
    Last Post: July 17th, 2011, 02:17 PM
  3. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM
  4. Strange launch problem using command prompt
    By Asido in forum Java Theory & Questions
    Replies: 2
    Last Post: September 15th, 2010, 07:52 AM
  5. Unable to launch app of java application
    By sharmaneelam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 19th, 2010, 08:42 AM