NombreDelPrograma.java
Categorías: CategoryJava | CategoryProgramacion |
1 package Falsa;
2
3 import java.io.*;
4 import java.net.*;
5 import java.util.logging.Level;
6 import java.util.logging.Logger;
7
8 /**
9 * esta clase servira como prueba pra ver si el juego funciona de manera que
10 * el servidor pueda jugar con uno o varios jugadores en diferntes pc's
11 *
12 * @author Jennifer
13 */
14
15 public class ServidorPrueba {
16
17 /**
18 *este atributo llamado puerto es el puerto para la
19 * conexion del socket
20 */
21
22 public static final int puerto = 9999;
23
24 /**
25 *
26 * @param args
27 * @throws IOException son lo argumentos en la linea de comando
28 * el try y el catch estan cumpliendo la funcion de
29 * depurar los posibles errores que se encuentren en el moneto de ejecutar el archivo
30 */
31
32
33 public static void main(String[] args) {
34 ServerSocket socketEscucha = null;
35 Socket socket = null;
36 DataInputStream entrada = null;
37 String mensaje;
38 try {
39 socketEscucha = new ServerSocket(puerto);
40 } catch (IOException ex) {
41 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
42 }
43 try {
44 socket = socketEscucha.accept();
45 } catch (IOException ex) {
46 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
47 }
48 try {
49 entrada = new DataInputStream(socket.getInputStream());
50 } catch (IOException ex) {
51 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
52 }
53 try {
54 while ((mensaje = entrada.readLine()) != null) {
55 System.out.println(mensaje);
56 }
57 } catch (IOException ex) {
58 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
59 }
60 try {
61 socket.close();
62 } catch (IOException ex) {
63 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
64 }
65 try {
66 socketEscucha.close();
67 } catch (IOException ex) {
68 Logger.getLogger(ServidorPrueba.class.getName()).log(Level.SEVERE, null, ex);
69 }
70 }
71 }
