Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse Examples » UDP CHAT + Java(How can I do..//Como puedo hacer..)
UDP CHAT + Java [message #1139083] Tue, 15 October 2013 14:25 Go to next message
Borja Hazas Espiga is currently offline Borja Hazas Espiga
Messages: 2
Registered: October 2013
Junior Member

Hi, I am doing a udp chat with Java in Eclipse.
I have two classes Chat Client and Chat Server, the first of this one,contains the JFrame of what comes to be the chat screen, the main and a controller that manages connections to the server. The Chat Server has a Message and User.

The problem is that in the ChatClientController I have problems when implementing the functions: connecting ... disconnecting ...
I use a socket to send datagrams (messages)

If you can help me, I would be very grateful.
I can send you the code of the classes, if necessary.
-------------------------------------------------------
Hola, estoy realizando un chat udp, cuento con dos clases Chat Client y Chat Server, el primero de ellos tengo el JFrame de lo que viene a ser la pantalla del chat, el main y un controller que gestiona las conexiones con el servidor. El Chat Server tiene un Message y User.

El problema es que en el ChatClientController tengo problemas a la hora de implementar las funciones de conectar...desconectar...utilizo un socket para mandar los datagramas(mensajes)

Si me podeis ayudar, estarĂ­a muy agradecido.
Puedo enviaros las clases por si es necesario.
Re: UDP CHAT + Java [message #1143538 is a reply to message #1139083] Fri, 18 October 2013 08:54 Go to previous message
Borja Hazas Espiga is currently offline Borja Hazas Espiga
Messages: 2
Registered: October 2013
Junior Member
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);
}
}
Previous Topic:tomcat preference page
Next Topic:Open Sound Control (OSC)
Goto Forum:
  


Current Time: Tue Sep 23 04:39:17 GMT 2014

Powered by FUDForum. Page generated in 0.04744 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software