basic client/server structure
This commit is contained in:
35
ChatApp/src/client/Client.java
Normal file
35
ChatApp/src/client/Client.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
|
||||
import network.protocol.packets.LoginPacket;
|
||||
import network.protocol.packets.SendChatMessagePacket;
|
||||
|
||||
public class Client {
|
||||
|
||||
private final ClientConnexion connexion;
|
||||
|
||||
public Client(InetSocketAddress serverAddress) throws SocketException {
|
||||
this.connexion = new ClientConnexion(new DatagramSocket(), serverAddress);
|
||||
login("Moi");
|
||||
}
|
||||
|
||||
private void login(String pseudo) {
|
||||
try {
|
||||
this.connexion.sendPacket(new LoginPacket(pseudo));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void SendChatMessage(String message) {
|
||||
try {
|
||||
this.connexion.sendPacket(new SendChatMessagePacket(message));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user