Chat-Applikation/src/client/MainClient1.java

68 lines
1.8 KiB
Java
Raw Normal View History

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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);
}
}
}
}
}