0

I have made a 2 player game in java for my class but I am looking to make it online. Currently it is set up and running on my localhost socket = new Socket("localhost", 30000);. However I have been reading into how to set up a server. I have set up an AWS account and have an instance if EC2 up and running with java installed on it. I am hoping someone can tell me how do I set up the server or are there any good tutorials on setting up the server on EC2. Also when it is set up what do I replace localhost with?

Thank you so much!

7
  • There are many web tutorials and videos that can help you deploy a Java webapp onto EC2. Commented Jan 24, 2021 at 20:05
  • It is not a Java webapp as far as I know. It has nothing to do with servlets etc. so I dont think the tutorials are helpful, unless I am misunderstood Commented Jan 24, 2021 at 20:15
  • I'm assuming that your Java app creates a socket so that it can listen for inbound messages. So, while it's not an HTTP server that listens on port 80 or 443, it's still a server of sorts and needs to solve similar problems to a deployed webapp. Do you plan to simply connect over SSH to the machine so you can run your app at the command line on an ad hoc basis or do you plan for it to run, unattended, 24x7? Commented Jan 24, 2021 at 20:24
  • Yes exactly. The app creates a server socket and listenes for when players connect to the game and listens to information players send it. I think I would want to just connect over SSH as I only need to start the server when I am going to play the game. How would I go about doing this? Should I use elastic beanstalk as suggested? Thanks for your time! Commented Jan 24, 2021 at 20:30
  • In that case, I'd probably not use Beanstalk because you'd be paying for more infrastructure and more time. I'd consider a simple EBS-backed EC2 instance and set up your app to run under the control of systemd (if Ubuntu) or pm2 or some other service/process manager. Stop your EC2 instance when you don't need it and start it when you need it, to reduce cost. Commented Jan 24, 2021 at 20:50

1 Answer 1

1

I am hoping someone can tell me how do I set up the server

Same way you run it on your local computer. Just... run it. ssh into your EC2 server as normal and run java -jar yourapp.jar. There's nothing magical going on.

Also when it is set up what do I replace localhost with?

The IP address of your server, which is listed in the AWS console.

Note that you'll need to configure the security group that your AWS instance is in, and open up port 30000.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I push my folder into the EC2 server. I am trying this scp -i "cameronKenny.pem" TurnbasedNetworkingGame.tar.xz ec2-user@ec2-54-155-231- 59.eu-west-1.compute.amazonaws.com:/usr/java/ . However i keep getting this error: /usr/libexec/grepconf.sh: line 5: grep: command not found bash: scp: command not found lost connection

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.