コード例 #1
0
 void serv(int i) {
   try {
     S = new DatagramSocket(i);
     S.setSoTimeout(5000);
   } catch (Exception exception) {
     exception.printStackTrace();
     if (S != null)
       try {
         S.close();
       } catch (Exception exception2) {
       }
     return;
   }
   System.out.println(DF.format(new Date()) + "Waiting connections ...");
   do
     try {
       buf = new byte[256];
       P = new DatagramPacket(buf, buf.length);
       S.receive(P);
       Connection connection =
           (Connection) Connections.get(P.getAddress().toString() + P.getPort());
       if (connection == null) {
         System.out.println(
             DF.format(new Date())
                 + "Connect from "
                 + " ("
                 + P.getAddress().getHostAddress()
                 + ")");
         connection = new Connection(this, P);
         Connections.put(P.getAddress().toString() + P.getPort(), connection);
         connection.start();
       } else {
         connection.packet(P);
       }
     } catch (Exception exception1) {
     }
   while (true);
 }
コード例 #2
0
 void closeConnection(Connection connection) {
   Connections.remove(connection.Address.toString() + connection.Port);
 }