-
Notifications
You must be signed in to change notification settings - Fork 12
Server
#Server#
##What We'll Most Likely Be Using##
Hey gang,
It looks like if the iOS and Android groups are going to be developing in HTML5/JavaScript, we're going to be using a protocol called WebSockets to communicate with them -- it should make things quite easy (hopefully).
To do this, I think we'll be using jWebSocket which provides a wrapper above the JavaScript websocket interface thingy that we can use in Java. So go read up on it! There are a number of github projects that use this interface, so we have lots of example code.
Let me know what you think!
##Databases Information##
(9-26-11) After working in the mongodb shell, I've realized that this is a lot more functional and useful than the other databases we've been looking at. Their website notes: "mongo is a full JavaScript shell, so any JavaScript function, syntax, or class can be used in the shell." This makes interaction through the shell incredibly easy to use. This implies that the Javascript code we write for it may also be easy to handle. :D
Besides being easy to use, mongodb is also incredibly fast and flexible. We'll still have to flesh out a bit of design before we go willy nilly jamming peanut butter into a database that will monitor the games, but we'll have a bit more wiggle room if we drop some peanuts it (with an easily understood syntax to boot).
I know we haven't gotten far enough to warrant it, but anyone interested in messing around with the database should check out their tutorial (http://www.mongodb.org/display/DOCS/Tutorial).
(Irrelevant) As relational databases aren't the most ideal for the real-time data access Vir-Pong requests, I suggest a noSQL document-based database. The two that seem most plausible are OrientDB (http://www.orientechnologies.com/) and Terrastore (http://code.google.com/p/terrastore/wiki/Java_Client_API). Both have Java API interfaces.
#Planning Data Organization#
(9-12-11) If we are going to follow through in using MySQL (though I find no reason why we wouldn't) we're going to have to require more communication with the other groups. Relational databases aren't ideal for real time data so we have to determine what method we want to store it in and how quickly we want to store it and how quickly we want to access it. However, this all depends on what information we're storing. We'll need to determine what sort of things we'll be handling soon so we can start planning how our database will run.
##Accessing MySQL through Java##
MySQL Connector/J is a JDBC driver to allow one to code in Java to mySQL. All of the advanced computer lab machines should have this installed on them, as well as MySQL itself (the driver can be downloaded at http://dev.mysql.com/usingmysql/java/ ). However, even when coding with Java, you must use SQL commands to communicate with the database.
For example, let's say you have a connection to the database called 'conn'. If we want to call a query on people (a table in the database) where their ID is less than 4 and their names are returned in an order based on the numerical order of the ID, then we would write something like:
'conn.createStatement().executeQuery("SELECT name
FROM people
WHERE id
< 4 ORDER BY id
);'
SQL in itself is relatively easy to understand and there are many accessible tutorials on the internet. But it raises the question of whether we should attempt to find alternative solutions or have the group learn SQL.
#Running A Server Using Java#
It is possible to run a server in Java and there are many tutorials with a google search of Java Web Server. An example of a tutorial that allows you to set up a server in Java is http://fragments.turtlemeat.com/javawebserver.php.
Here is some sample code:
//file: server.java
//the real (http) serverclass
//it extends thread so the server is run in a different
//thread than the gui, that is to make it responsive.
//it's really just a macho coding thing.
public class server
extends Thread {
//the constructor method
//the parameters it takes is what port to bind to, the default tcp port
//for a httpserver is port 80. the other parameter is a reference to
//the gui, this is to pass messages to our nice interface
public server(int listen_port, webserver_starter to_send_message_to) {
message_to = to_send_message_to;
port = listen_port;
//this makes a new thread, as mentioned before,it's to keep gui in
//one thread, server in another. You may argue that this is totally
//unnecessary, but we are gonna have this on the web so it needs to
//be a bit macho! Another thing is that real pro webservers handles
//each request in a new thread. This server dosen't, it handles each
//request one after another in the same thread. This can be a good
//assignment!! To redo this code so that each request to the server
//is handled in its own thread. The way it is now it blocks while
//one client access the server, ex if it transferres a big file the
//client have to wait real long before it gets any response.
this.start();
}
private void s(String s2) { //an alias to avoid typing so much!
message_to.send_message_to_window(s2);
}
private webserver_starter message_to; //the starter class, needed for gui
private int port; //port we are going to listen to
So we should be able to make a server in Java.
##An alternative(of some sort)## I have not been able to find much about how coding with it works but a definite alternative is Apache Tomcat. It is open source and it is supposed to run Java in a pure environment. I take that to mean that it runs Java really well.
A short tutorial exists here: http://www.vogella.de/articles/ApacheTomcat/article.html#tomcatoverview and I am sure that there are more in depth ones ones out there.
##How to open a port on a server using java websites## http://www.java2s.com/Code/Java/Development-Class/OpenaserialportusingJavaCommunications.htm
http://www.java-samples.com/showtutorial.php?tutorialid=11
##Some links about servlets## Here are the top websites with servlet info. It is basically an application that is written on the sever side and handles certain information. The javadocs give a good idea of what they can do. We may need them when the phones are trying to communicate to the server...
http://www.novocode.com/doc/servlet-essentials/chapter1.html
http://java.sun.com/javaee/6/docs/api/javax/servlet/package-summary.html