Chat-Applikation/src/client/MainClient.java

66 lines
1.8 KiB
Java

package client;
import java.io.*;
import java.net.*;
public class MainClient {
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);
try {
System.out.println("Sleepin for 5 seconds");
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println("Thread is interrupted");
}
} 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);
}
}
}
}
}