Eclipse - UDP Chat

 
Vista:
sin imagen de perfil

UDP Chat

Publicado por Borja (2 intervenciones) el 15/10/2013 16:02:53
Hola,
estoy implementando un chat UDP en Eclipse, pero me he quedado pillado cuando me han pedido que realice algunas modificaciones. La primera de ellas es crear un controller que gestiones conexiones, desconexiones..etc
Teneis algún ejemplo de como puedo hacerlo????
Si es necesario os pego el codigo.
Un saludo.
Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

UDP Chat

Publicado por Borja (2 intervenciones) el 15/10/2013 16:29:04
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java.net.DatagramSocket;
import java.util.ArrayList;
import java.util.List;
import java.util.Observer;
 
import es.deusto.ingenieria.ssdd.util.observer.local.LocalObservable;
import es.deusto.ingenieria.ssdd.chat.data.User;
 
public class ChatClientController {
	private String serverIP;
	private int serverPort;
	private User connectedUser;
	private User chatReceiver;
	private LocalObservable observable;
 
	public ChatClientController() {
		this.observable = new LocalObservable();
		this.serverIP = null;
		this.serverPort = -1;
	}
 
	public String getConnectedUser() {
		if (this.connectedUser != null) {
			return this.connectedUser.getNick();
		} else {
			return null;
		}
	}
 
	public String getChatReceiver() {
		if (this.chatReceiver != null) {
			return this.chatReceiver.getNick();
		} else {
			return null;
		}
	}
 
	public String getServerIP() {
		return this.serverIP;
	}
 
	public int gerServerPort() {
		return this.serverPort;
	}
 
	public boolean isConnected() {
		return this.connectedUser != null;
	}
 
	public boolean isChatSessionOpened() {
		return this.chatReceiver != null;
	}
 
	public void addLocalObserver(Observer observer) {
		this.observable.addObserver(observer);
	}
 
	public void deleteLocalObserver(Observer observer) {
		this.observable.deleteObserver(observer);
	}
 
	public boolean connect(String ip, int port, String nick) {
 
		//CODE
 
		try
		{
			DatagramSocket udpSocket = new DatagramSocket();
 
		}
		catch(Exception e){
		}
 
		this.connectedUser = new User();
		this.connectedUser.setNick(nick);
		this.serverIP = ip;
		this.serverPort = port;
 
		return true;
	}
 
	public boolean disconnect() {
 
		//CODE
 
		this.connectedUser = null;
		this.chatReceiver = null;
 
		return true;
	}
 
	public List<String> getConnectedUsers() {
		List<String> connectedUsers = new ArrayList<>();
 
		//CODE
		connectedUsers.add("Default");
 
		return connectedUsers;
	}
 
	public boolean sendMessage(String message) {
 
		//CODE
 
		return true;
	}
 
	public void receiveMessage() {
 
		//CODE
 
		String message = "Received message";
 
		//Notify the received message to the GUI
		this.observable.notifyObservers(message);
	}
 
	public boolean sendChatRequest(String to) {
 
		//CODE
 
		this.chatReceiver = new User();
		this.chatReceiver.setNick(to);
 
		return true;
	}
 
	public void receiveChatRequest() {
 
		//CODE
 
		String message = "Chat request details";
 
		//Notify the chat request details to the GUI
		this.observable.notifyObservers(message);
	}
 
	public boolean acceptChatRequest() {
 
		//CODE
 
		return true;
	}
 
	public boolean refuseChatRequest() {
 
		//CODE
 
		return true;
	}
 
	public boolean sendChatClosure() {
 
		//CODE
 
		this.chatReceiver = null;
 
		return true;
	}
 
	public void receiveChatClosure() {
 
		//CODE
 
		String message = "Chat request details";
 
		//Notify the chat request details to the GUI
		this.observable.notifyObservers(message);
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar