-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServidor.java
73 lines (63 loc) · 2.19 KB
/
Servidor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;
import java.util.Scanner;
public class Servidor {
public static Socket[] tabSocket= new Socket[100];
public static int i;
public static void main(String args[]){
ServerSocket listenSocket;
i=1;
Scanner sc = new Scanner(System.in);
try {
BufferedReader socIn = null;
Socket clientSocket;
listenSocket = new ServerSocket(2000); //port
while (true) {
System.out.println("Servidor general listo");
clientSocket = listenSocket.accept();
socIn = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String Name = socIn.readLine();
ServidorThread ct = new ServidorThread(clientSocket,i,Name);
i++;
System.out.println("[Servidor Central] Dar autorizacion a"+ clientSocket.getInetAddress()+" por Distrito "+ Name +"?");
System.out.println("1-Si");
System.out.println("2-No");
String ans = sc.nextLine();
//while(true) {
if (ans =="1") {
ct.run();
break;
}
else if (ans=="2")
{
ct.run();
//ct.exit=true;
System.out.println("à enlever");
break;
}
/**System.out.println("1-Si");
System.out.println("2-No");
ans=sc.nextLine();
}**/
}
/**MulticastSocket socket = new MulticastSocket(2000);
//Receive request from client
for(int i=0; i < str.length; i++){
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, str[i], port);
socket.receive(packet);
addresStr[i] = packet.getAddress().toString();
InetAddress client = packet.getAddress();
int client_port = packet.getPort();
area.append("Received : '" + new String(buffer).trim() + "' from " + addresStr[i] + "\n");
// send information to the client
String message = "your request\n ";
buffer = message.getBytes() ;
packet = new DatagramPacket(buffer, buffer.length, client, client_port);
socket.send(packet);
}**/
} catch (Exception e) {
System.err.println("Error in ServerChat:" + e);
}
}
}