Chat-Applikation/src/client/MainClient1.java

79 lines
2.3 KiB
Java
Raw Normal View History

/*
* Copyright (C) 2021 eichehome
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client;
import java.io.*;
import java.net.*;
/**
* Hauptklasse des Clients
* @version 0.0.1
* @author eichehome
*/
public class MainClient1 {
static Socket server = null;
static PrintWriter pr = null;
static BufferedReader bf = null;
static InputStreamReader in = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
server = new Socket("localhost", 1236);
pr = new PrintWriter(server.getOutputStream());
pr.println("is it working?");
pr.flush();
in = new InputStreamReader(server.getInputStream());
bf = new BufferedReader(in);
String str = bf.readLine();
System.out.println("server: " + str);
} catch (IOException e) {
System.err.println("Fehler: " + e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
System.err.println("Fehler: " + e);
}
}
if (bf != null) {
try {
bf.close();
} catch (IOException e) {
System.err.println("Fehler: " + e);
}
}
if (pr != null) {
pr.close();
}
if (server != null) {
try {
server.close();
} catch (IOException e) {
System.err.println("Fehler: " + e);
}
}
}
}
}