Browse Source

Create connection to server using socket

remotes/origin/feature/client/exchange-messages-between-client-server
Alena Bandarovich 11 months ago
parent
commit
aa10ff56c6
  1. 23
      src/main/java/ChatClient.java

23
src/main/java/ChatClient.java

@ -1,12 +1,31 @@
import javax.swing.*; import javax.swing.*;
import java.io.IOException;
import java.net.Socket;
public class ChatClient { public class ChatClient {
private String address; private String address;
public ChatClient() {
private int port;
private Socket connectionToServer;
public ChatClient(int port) {
this.port = port;
address = JOptionPane.showInputDialog("bitte IP-Adresse"); address = JOptionPane.showInputDialog("bitte IP-Adresse");
if (address != null) {
receiveMessages();
}
}
private void receiveMessages() {
try {
connectionToServer = new Socket(address, port);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
}
} }
public static void main(String[] args) { public static void main(String[] args) {
new ChatClient();
new ChatClient(3141);
} }
} }
Loading…
Cancel
Save