14 Replies - 5425 Views - Last Post: 03 January 2011 - 09:32 PM Rate Topic: -----

#1 feamor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-January 11

java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:02 PM

I am trying to make multiplayer an online Battleship game with java applets and i have some questions.

  • I searched and read a lot and decide that the best way to make an online multiplayer battleship game is by using p2p. Client applets communicate with each other over datagram sockets. And there should be a server which the clients connect. This will show all clients that are connected and players can send invitation to other clients from list and start the game. When the game starts, the server transfers the messages between clients (the shots and where the battleships are placed) over datagramsockets. When user A sends a message to user B, server receives the message of user A and sends it to user B.

    Is it a good choice to make the design of the game like this? (Sending the messages over datagramsockets (UDP) and a server between all clients. Can you suggest any other way? (I should use java and the game should be played on browser)

  • How can i start the server side of this application? I saw some application which client side is coded as applets and server as application. On my computer, i can start the server by doubleclicking the jar file or running from Eclipse, then run the client applets from web browser(by using WAMP) or from Eclipse and it works perfect.
    But when i try the same thing in a web server, there isn't any problem about running the client applets but i can't find out how can i start the server before running the clients and the server shouldn't be closed if i don't want? How can i run the server from browser on a web server? (if it is written as application, not applet) Can the server be written as applets? Do you have any other suggestions?

This post has been edited by feamor: 02 January 2011 - 07:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: java game applets and how to start the server in a client-server web a

#2 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:15 PM

There is such a thing called a Servlet, it's basiscally a Java based server's API. This is known as a JSP (Java Server Page). You program it like any other Java application, except the class file runs whenever a request is made to that page on the server. Not all servers supports JSP, but now and days most servers support just about anything. :)
I'm not really sure, but I think the Apache Tomcat Server can be used to run JSP pages and is available as a default in Eclisp. Here's a nice tutorial on this.
As to your other question, I think using P2P has it's risks. Most likely a successful connnection will not be stable (if not unestablishable) using UDP for a persist connection. It also makes reconnecting almost impossible (to my knowledge, I may be wrong). The other thing is an user might not have a static IP address, as some ISP does do that.

This post has been edited by Jimmy.Li: 02 January 2011 - 07:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:23 PM

Using a Servlet for that type of thing is like using a Cadillac to deliver a Pizza
Just build an application that can be run as Server or Client (depending on the parameters passed at run time) and connect to the first one (started as server) as a client.
Was This Post Helpful? 1
  • +
  • -

#4 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:33 PM

What's wrong with devlivering in style? :P The server application would most likely have to run on a server... in the form of a JSP. Although that is probably a good place to start, it won't be very hard to transform your Server application into a Servlet.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:41 PM

View PostJimmy.Li, on 02 January 2011 - 08:33 PM, said:

What's wrong with devlivering in style? :P The server application would most likely have to run on a server... in the form of a JSP. Although that is probably a good place to start, it won't be very hard to transform your Server application into a Servlet.

We are dealing with a newbie here who probably had never written a client/server application
Your solution requires:
- J2EE
- a workable server
I think that this is way ahead (without offense) of the OP knowledge
Was This Post Helpful? 0
  • +
  • -

#6 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 07:54 PM

View Postpbl, on 02 January 2011 - 06:41 PM, said:

We are dealing with a newbie here who probably had never written a client/server application
Your solution requires:

I can say with almost certainty the OP is not a newbie, as he or she is developing a full on game application with sufficient knowledge of the TCP/IP protocol suite. The Eclispe IDE is designed for enterprise development, so I think it would have J2EE preinstalled (if not, it is only a few addon packs away). There is also, I think, a built server in the Eclispe IDE (if not Tomcat) that would most likely have JSP support. It's always good to find new ways to a solution, how one evaluates them is at their own disposal. Also, I think if this application is to put on a server, a server is inevitable.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 02 January 2011 - 08:09 PM

Really do not agree with you

The newbie

Quote

1.I searched and read a lot and decide that the best way to make an online multiplayer battleship game is by using p2p.


Quote

Is it a good choice to make the design of the game like this? (Sending the messages over datagramsockets (UDP) and a server between all clients. Can you suggest any other way?


Quote

2.How can i start the server side of this application?


Quote

Can the server be written as applets? Do you have any other suggestions?

Was This Post Helpful? 1
  • +
  • -

#8 feamor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-January 11

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 03:22 AM

@Jimmy.Li
Thank you for your quick reply. I am thinking to work on JSP, JSF and Servlets but after finishing that project :rolleyes2:
I don't know anything about them yet and i think it will take some time to learn how they work which i can't overcome now(I am working on this project for weeks and it should be finished a.s.a.p. :/ ). Maybe, JSP is the best choice for my application but i think it can also be done with JApplet and UDP or TCP/IP(I hope so because the only thing i read about and gain some experience is those)

@pbl
I have some experience on Java Programming, OOP, PHP and HTML but this my first web project written in Java using TCP/IP (or UDP). I have found some examples with source codes that are written without JSP. The first one is MagnificentBall which is a P2P game but not coded to work on browser. The other one is tic-tac-toe which is very similar with what i want. I can play this game on Eclipse by running TicTacToeServer, then starting TicTacToeClient Applet twice. But when i put this game on a web server and try to play it over net, i can't figure out how to start the server which waits for client connections when online(In Eclipse, i simply run the server but on web, i have no idea how to do which is the subject of my second question in my first post.)

And this instant messenger app. is like nearly what i want. From client applets, you can see other people who are connected to the server. By clicking on the name, you select who you want your message is sent to. When you type your message and press send, your message is send over datagramsocket as datagram packets. The server receives your message, opens and finds who is the receiver and delivers to the receiver client. Again, i can run this app. on Eclipse without any problem but can't run on web because don't know how to start the server class which extends JFrame. (I can send the program and source codes because i couldn't attach rar file to message. If you wish, you can download it from here by clicking "İndirmek išin tıklayın, umarım işinize yarar."
Was This Post Helpful? 0
  • +
  • -

#9 feamor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-January 11

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 03:50 AM

And another question, can i use swing in servlets(JSP)? On client side of the game, users see two boards divided into cells. Users place his/her ships on the left board(clients see their board on left). And attacks a cell from opponents board one per turn which is on right. I made these part of the game with JPanel. When opponent attacks to players board, you should take the point where he/she clicked and deliver these points or arrays between them which is the TCP/IP, UDP or JSP part of the game that i can't solve yet.
Was This Post Helpful? 0
  • +
  • -

#10 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 02:26 PM

View Postfeamor, on 03 January 2011 - 02:50 AM, said:

can i use swing in servlets(JSP)?

Not exactly relevent, a servelet is the code that processes a HTTP request and there would be no point for a GUI. :)
If you just want to start your JAR file on the server so that your client can connect to it, you can invoke the process with any script (PHP, ASP.NET, etc.) that is run on the server. This script executes once you vist the page in your browser and the connection should persist if your process does not terminate.
Of course, a better solution would to actually change the server's configurations so that the JAR file runs on startup (if you have the ability to do so on your server)... but since your server most likely won't be shutdown anyways, I think the prior solution would work also.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 04:01 PM

Second time I agree with Jimmy.Li this year :)
The server part should only handle data processor not GUI at all. The server part should completly ignore if the requester is console based or GUI based.
Was This Post Helpful? 0
  • +
  • -

#12 feamor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-January 11

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 04:55 PM

So if the client part is applet with gui, and the data i transfer between clients are objects, arrays or varriables, it won't be problem?
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 08:11 PM

In the best world is the way it should work
Was This Post Helpful? 0
  • +
  • -

#14 Jimmy.Li  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 57
  • Joined: 12-October 10

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 09:19 PM

View Postfeamor, on 03 January 2011 - 03:55 PM, said:

So if the client part is applet with gui, and the data i transfer between clients are objects, arrays or varriables, it won't be problem?

You should use the ObjectStream stream wrapper on top of your data stream, many built-in types in Java are Serializable (which is an interface), which means they have built-in methods to put it self into data and then back into an object (Very convient). The thing is though, the reciever of the data must also have the exact same version of the same class or things gets a little complicated (but can be done with versioning). :)
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: java game applets and how to start the server in a client-server web a

Posted 03 January 2011 - 09:32 PM

View PostJimmy.Li, on 03 January 2011 - 10:19 PM, said:

The thing is though, the reciever of the data must also have the exact same version of the same class or things gets a little complicated (but can be done with versioning). :)

Which will be the case if you write both :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1