コード例 #1
0
 public static void connectDatabase() {
   try {
     Class.forName("com.mysql.jdbc.Driver");
     String databaseURL = "jdbc:mysql://76.219.184.137:3306/PVPWorld";
     // Statement stmnt;
     databaseConnection = DriverManager.getConnection(databaseURL, "PVPWorldServer", "WarePhant8");
     // stmnt = con.createStatement();
     // stmnt.executeUpdate("CREATE TABLE myTable(test_id int,test_val char(15) not null)");
     // stmnt.executeUpdate("INSERT INTO myTable(test_id, test_val) VALUES(1,'One')");
     // stmnt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
     // ResultSet rs = stmnt.executeQuery("SELECT * from myTable ORDER BY test_id");
     // System.out.println("Display all results:");
     // while(rs.next()){
     // int theInt= rs.getInt("test_id");
     // String str = rs.getString("test_val");
     // System.out.println("\ttest_id= " + theInt
     // + "\tstr = " + str);
     // }//end while loop
   } catch (ClassNotFoundException e1) {
     e1.printStackTrace();
     System.exit(1);
   } catch (SQLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #2
0
 public static void openTCP() {
   try {
     serverTCPChannel = ServerSocketChannel.open();
     serverTCPChannel.configureBlocking(false);
     ss = serverTCPChannel.socket();
     ss.bind(new InetSocketAddress("localhost", 5472));
   } catch (IOException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #3
0
 public static void openUDP() {
   try {
     serverUDPConChannel = DatagramChannel.open();
     // serverUDPChannel = DatagramChannel.open();
     // serverUDPChannel.configureBlocking(false);
     serverUDPConChannel.socket().bind(new InetSocketAddress("localhost", 5472));
     serverUDPConChannel.configureBlocking(false);
   } catch (IOException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #4
0
 public static void finalizeConnections() {
   for (int i = 0; i < attemptedConnections.size(); i++) {
     if (attemptedConnections.get(i).finishConnect()) {
       if (attemptedConnections.get(i).hasUDPConnection()) {
         playerConnections.add(attemptedConnections.remove(i));
         --i;
         System.out.println("Connection Accepted");
       }
     } else {
       if (System.currentTimeMillis() - attemptedConnections.get(i).getTimeCreated() > 5000) {
         attemptedConnections.remove(i);
         --i;
         continue;
       }
     }
   }
 }