-
Notifications
You must be signed in to change notification settings - Fork 0
/
Echoserver.java~
55 lines (50 loc) · 1.64 KB
/
Echoserver.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
/**
* Write a description of class Echoserver here.
*
* @author Norbert Gutsche
* @version 02.05.2012
*/
public class Echoserver extends Server
{
// instance variables - replace the example below with your own
private final String ENDE = "*bye*";
/**
* Constructor for objects of class Echoserver
*/
public Echoserver()
{
super (2000); //Port 2000 ist der Port des Echoservers
}
/**
* Wenn ein Client anfragt, bekommt er auftomatisch diese Verbindung
* und somit diesen Satz geschickt!
*/
public void processNewConnection(String pClientIP, int pClientPort)
{
this.send(pClientIP, pClientPort, "Willkommen " + pClientIP +
" auf Port " + pClientPort + " beim Echo-Server!");
System.out.println("Willkommen " + pClientIP +
" auf Port " + pClientPort + " beim Echo-Server!");
}
public void processMessage(String pClientIP, int pClientPort, String pMessage)
{
if (pMessage.equals(ENDE))
{
this.closeConnection(pClientIP, pClientPort);
}
else
{
this.send(pClientIP, pClientPort, pClientIP + " " + pClientPort
+ ": " + pMessage);
System.out.println(pClientIP + " " + pClientPort
+ ": " + pMessage);
}
}
public void processClosedConnection(String pClientIP, int pClientPort)
{
this.send(pClientIP, pClientPort, pClientIP + " " + pClientPort +
" auf Wiedersehen");
System.out.println(pClientIP + " " + pClientPort + " auf Wiedersehen");
this.send(pClientIP, pClientPort, ENDE);
}
}